Skip to main content

Can I run Databricks notebooks outside the workspace?

Summary

  • Yes. You can open and run Databricks notebooks in Visual Studio Code or Cursor on your machine while the code executes on Databricks compute.
  • With the SSH tunnel (Beta), the notebook kernel itself runs on Databricks serverless compute, AI Runtime or a dedicated cluster, and .ipynb notebooks get Databricks globals such as spark, dbutils and display, plus %sql.
  • With the Databricks IDE extension and Databricks Connect, cells run locally and only Spark DataFrame work runs on Databricks, so %pip installs packages on your local machine.
  • The IDE extension can also run Python, R, Scala and SQL notebooks as Lakeflow Jobs in your workspace.
  • Databricks exports notebooks as source files or .ipynb files, and Databricks Connect lets a notebook server you run yourself send Spark work to Databricks.

Can I run Databricks notebooks outside the workspace?

Yes. You can edit and run a Databricks notebook in a local IDE while Databricks compute does the work. There are two documented ways, and they differ in one important respect: where each cell actually runs. The SSH tunnel puts the whole notebook kernel on Databricks compute, so the notebook behaves much as it does in the workspace. The Databricks IDE extension with Databricks Connect runs cells on your laptop and sends only Spark operations to Databricks.

Two ways to run notebooks from an IDE

SSH tunnel (Beta) IDE extension + Databricks Connect
Where cells run On Databricks compute Locally; DataFrame operations on Databricks
Notebook formats .ipynb and Python source notebooks .py and .ipynb
Databricks globals in .ipynb spark, dbutils, display, displayHTML, sql, table, udf, sc and more spark, dbutils (a subset), display, displayHTML, sql, udf
%pip installs to The remote environment Your local machine
Editors Visual Studio Code, Cursor Visual Studio Code, Cursor

What to check before you choose

  • Where code should run. If code beyond Spark calls must run on Databricks, such as plain Python over files in /Workspace or /Volumes, or the cluster's preinstalled libraries, use the SSH tunnel.
  • Debugging. The extension's Databricks Connect integration adds Run Cell, Run Above and Debug Cell for .py notebooks, with breakpoints, variable watches and the call stack.
  • Languages. In the extension, %r and %scala magics return errors. R, Scala and SQL notebooks can still run as jobs.
  • Tool conflicts. The docs say the SSH tunnel and the IDE extension "are not compatible and should not be used together."

How Databricks runs notebooks outside the workspace

Over the SSH tunnel. Connect with databricks ssh connect --ide vscode (or --ide cursor), open /Workspace/Users/<your-username>, and select the pythonEnv-xxx environment as the notebook kernel with Select Kernel. From then on, the SSH tunnel docs say you "run and debug Python files and .ipynb notebooks using the standard Python and Jupyter extensions," with the environment and execution on remote compute.
Databricks Python source notebooks, the .py files that begin with # Databricks notebook source, need two Jupyter settings so the IDE recognizes their cells. Set jupyter.interactiveWindow.cellMarker.default to:

# COMMAND ----------

and set jupyter.interactiveWindow.cellMarker.codeRegex to the pattern given in the docs. Plain Python files don't get Databricks globals; import them explicitly:

from databricks.sdk.runtime import spark

Two limits to plan around: the docs warn of performance or connection issues "when three or more Jupyter notebooks are open simultaneously," and inactive sessions might drop after an hour.
With the IDE extension and Databricks Connect. The notebook guide for the extension runs cells one at a time or all at once and shows results in Visual Studio Code. All code runs and is debugged locally, while "all Spark code continues to run on the cluster in the remote Databricks workspace." It needs Databricks Runtime 13.3 and above. A few magics need local packages: %run requires pip install nbformat, and dbutils.widgets requires pip install 'databricks-sdk[notebook]'.
As a job. The extension can run Python, R, Scala and SQL notebooks as Lakeflow Jobs in your workspace. Use it when you want a job run rather than an interactive session.
In your own notebook server. The import and export docs cover source files (.py, .scala, .sql, .r) and IPython notebooks (.ipynb). To keep Spark work on Databricks from a notebook server you run, Databricks Connect is the documented path for connecting notebooks to Databricks compute, using a DatabricksSession in place of a local Spark session.

FAQs

Do dbutils and display() work when I run a notebook in my IDE?

Over the SSH tunnel, .ipynb notebooks get dbutils, display and the other Databricks globals. With the IDE extension, display maps to the IPython display function and only a subset of Databricks Utilities is supported.

Where does %pip install put packages?

Over the SSH tunnel, %pip installs into the remote environment and propagates to Spark executors, so UDFs can use the packages. With the IDE extension and Databricks Connect, %pip runs pip install on your local machine.

Can I run Scala or R notebooks in Visual Studio Code?

The IDE extension runs R, Scala and SQL notebooks as jobs but doesn't offer deeper support for those languages in the editor, and the %r and %scala magics aren't supported in cell runs.

Is running notebooks over the SSH tunnel generally available?

No. The SSH tunnel is in Beta, and the docs say cost and pricing for Beta features are subject to change.

The information provided herein is for general informational purposes only and may not reflect the most current product capabilities or configurations.