Loading...
Loading...
Execute code and manage compute on Databricks: run Python/Scala/SQL/R via serverless, classic, or interactive clusters, and create/resize/delete clusters and SQL warehouses.
npx skill4agent add databricks/databricks-agent-skills databricks-execution-computedatabricks-core| Aspect | Databricks Connect ⭐ | Serverless Job | Interactive Cluster |
|---|---|---|---|
| Use for | Spark code (ETL, data gen) | Heavy processing (ML) | State across tool calls, Scala/R |
| Startup | Instant | ~25-50s cold start | ~5min if stopped |
| State | Within Python process | None | Via context_id |
| Languages | Python (PySpark) | Python, SQL | Python, Scala, SQL, R |
| Dependencies | | CLI with environments spec | Install on cluster |
databricks-dabsdatabricks bundle rundatabricks.ymlSpark-based code? → Databricks Connect (fastest)
└─ Python 3.12 missing? → Install it + databricks-connect
└─ Install fails? → Ask user (don't auto-switch modes)
Heavy/long-running (ML)? → Serverless Job (independent)
Need state across calls? → Interactive Cluster (list and ask which one to use)
Scala/R? → Interactive Cluster (list and ask which one to use)from databricks.connect import DatabricksSession
...
spark = DatabricksSession.builder.profile("my-local-profile").serverless(True).getOrCreate()
python my_spark_script.pydatabricks jobs submit# Databricks notebook source-- Databricks notebook sourceTARGET_PATH--filedatabricks workspace import /Workspace/Users/<user>/.ai_dev_kit/train --file /local/path/to/train.py --format SOURCE --language PYTHON --overwrite--no-wait{"run_id": N}"client": "4"dependencies"1"databricks jobs submit --no-wait --json @submit.json{
"run_name": "train-run",
"tasks": [{
"task_key": "main",
"notebook_task": {"notebook_path": "/Workspace/Users/<user>/.ai_dev_kit/train"},
"environment_key": "ml_env"
}],
"environments": [{
"environment_key": "ml_env",
"spec": {"client": "4", "dependencies": ["scikit-learn==1.5.2", "mlflow==2.22.0"]}
}]
}PENDINGRUNNINGTERMINATEDSKIPPEDINTERNAL_ERROR.state.result_stateSUCCESSFAILEDCANCELEDTERMINATEDdatabricks jobs get-run <RUN_ID> | jq '{state: .state.life_cycle_state, result: .state.result_state, duration_ms: .execution_duration, url: .run_page_url, task_run_id: .tasks[0].run_id}'get-run-output.tasks[0].run_idrun_idnotebook_output.resultdbutils.notebook.exit()databricks jobs get-run-output <TASK_RUN_ID> | jq '{result: .notebook_output.result, error, error_trace}'dbutils.notebook.exit(<string>)print()get-run-outputdbutils.notebook.exit(json.dumps({...})).notebook_output.result| Action | Command |
|---|---|
| Upload local file as workspace notebook | |
| Run serverless code (upload + submit + wait) | |
| Get run state / wait | |
| Fetch run output | |
| List clusters | |
| Get cluster details | |
| Start / restart / terminate cluster | |
| Permanently delete cluster | |
| Create cluster | |
| List node types / Spark versions | |
| Execute code on a running cluster | |
| SQL warehouses | |
ID--iddatabricks warehouses list# Create a serverless SQL warehouse. min_num_clusters + max_num_clusters are REQUIRED
# (the server rejects the default 0). Keep the aidevkit_project tag for resource tracking.
databricks warehouses create --json '{
"name": "my-warehouse",
"cluster_size": "Small",
"enable_serverless_compute": true,
"auto_stop_mins": 10,
"min_num_clusters": 1,
"max_num_clusters": 1,
"tags": {"custom_tags": [{"key": "aidevkit_project", "value": "ai-dev-kit"}]}
}'
# List / find — trim to id, name, state with jq
databricks warehouses list -o json | jq '.[] | {id, name, state, size: .cluster_size}'
# Find by name
databricks warehouses list -o json | jq '.[] | select(.name == "my-warehouse")'
# Get one warehouse's full config
databricks warehouses get <WAREHOUSE_ID>
# Start / stop (both are LROs; add --no-wait to return immediately)
databricks warehouses start <WAREHOUSE_ID>
databricks warehouses stop <WAREHOUSE_ID>
# Resize / reconfigure — pass the FULL desired config (omitted fields revert to defaults,
# so always re-state min_num_clusters/max_num_clusters). Use --no-wait if the warehouse
# is STOPPED, otherwise edit blocks trying to reach RUNNING and errors out (the mutation
# itself still applies). When the warehouse is already RUNNING, --no-wait is optional.
databricks warehouses edit <WAREHOUSE_ID> --no-wait --json '{
"name": "my-warehouse",
"cluster_size": "Medium",
"enable_serverless_compute": true,
"auto_stop_mins": 15,
"min_num_clusters": 1,
"max_num_clusters": 1
}'
# Delete (irreversible)
databricks warehouses delete <WAREHOUSE_ID>2X-SmallX-SmallSmallMediumLargeX-Large2X-Large3X-Large4X-Large"warehouse_type": "PRO""CLASSIC"