Skip to content

Add serverless code runner tool (Python, SQL, .ipynb — no cluster required)#278

Draft
GeorgeTheo99 wants to merge 3 commits intodatabricks-solutions:mainfrom
GeorgeTheo99:feature/serverless-code-runner
Draft

Add serverless code runner tool (Python, SQL, .ipynb — no cluster required)#278
GeorgeTheo99 wants to merge 3 commits intodatabricks-solutions:mainfrom
GeorgeTheo99:feature/serverless-code-runner

Conversation

@GeorgeTheo99
Copy link

Summary

  • New tool: run_code_on_serverless — Execute Python, SQL, or Jupyter notebooks (.ipynb) on Databricks serverless compute via the Jobs API (runs/submit). No cluster required.
  • Under the hood: uploads code as a temporary notebook, submits an ephemeral one-time run on serverless compute, retrieves output (including full error tracebacks), and cleans up the notebook automatically. Run URL is returned so the user can monitor progress.
  • Auto-detects .ipynb content and uploads via Databricks' native Jupyter import (ImportFormat.JUPYTER) — a net-new capability for the toolkit.
  • Includes MCP tool wrapper, skill documentation with decision matrix, and usage examples.

Files changed (4 files, +619 lines)

File Change
databricks-tools-core/.../compute/serverless.py Core implementation (new)
databricks-tools-core/.../compute/__init__.py Module exports
databricks-mcp-server/.../tools/compute.py MCP tool wrapper
databricks-skills/.../SKILL.md Skill documentation (new)

Key design decisions

  • Uses runs/submit (not jobs.create) — ephemeral one-time runs, no stale job definitions left behind
  • SQL SELECT results are intentionally not supported (Jobs API limitation) — documented to use execute_sql() instead
  • .ipynb detection is content-based (checks for "cells" key in JSON), no file extension needed
  • Error tracebacks are captured from run output on failure, not just the generic "Workload failed" message

Test plan

  • Unit tests (25/25 passed)
  • SQL integration tests (17/17 passed)
  • Compute integration tests (11/11 passed)
  • MCP server tests (35/35 passed)
  • Manual serverless Python execution (hello world, Spark + table read)
  • Manual serverless SQL DDL (CREATE TABLE, verified via execute_sql)
  • Manual error handling (ZeroDivisionError traceback, invalid language, empty code)
  • Manual .ipynb execution (Jupyter notebook with Spark, parsed JSON output)
  • Auto-detection logic (no false positives on plain code, plain JSON, malformed input)

🤖 Generated with Claude Code

George Theodosopoulos and others added 3 commits March 9, 2026 14:45
Adds a new `run_code_on_serverless()` function that executes Python or SQL
code on Databricks serverless compute using the Jobs API `runs/submit`
endpoint. No interactive cluster is required.

The implementation:
- Uploads code as a temporary notebook to the workspace
- Submits a one-time run with serverless compute (environments + environment_key pattern)
- Waits for completion and retrieves output via get_run_output
- Cleans up temporary workspace files after execution
- Returns a typed ServerlessRunResult with output, error, run_id, run_url, and timing

New files and changes:
- databricks-tools-core: compute/serverless.py (core module)
- databricks-tools-core: compute/__init__.py (exports)
- databricks-mcp-server: tools/compute.py (MCP tool wrapper)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
… improve docs

- Retrieve actual Python traceback on failure instead of generic "Workload
  failed" message by fetching run output in the exception handler
- Fix Optional[str] type annotation for run_name in MCP wrapper
- Document SQL SELECT output limitation in all docstrings
- Reframe tool as Python-first; clarify SQL is niche (DDL/DML only, use
  execute_sql for queries — works with serverless SQL warehouses)
- Add databricks-serverless-compute skill file with decision matrix,
  output capture behavior, limitations, and examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Auto-detects .ipynb JSON content and uploads via Databricks native
Jupyter import (ImportFormat.JUPYTER), enabling users to run local
Jupyter notebooks on serverless compute without conversion.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant