---
title: Run and debug notebook cells with Databricks Connect using the Databricks IDE extension
description: Learn how to run and debug notebooks in Visual Studio Code using the Databricks Connect integration in the Databricks extension for Visual Studio Code.
canonical_url: https://docs.databricks.com/aws/en/dev-tools/vscode-ext/notebooks
---

# Run and debug notebook cells with Databricks Connect using the Databricks IDE extension

You can run and debug notebooks, one cell at a time or all cells at once, and see their results in the Visual Studio Code UI using the Databricks IDE extension Databricks Connect integration. All code runs locally, while all code involving DataFrame operations runs on the cluster in the remote Databricks workspace and run responses are sent back to the local caller. All code is debugged locally, while all Spark code continues to run on the cluster in the remote Databricks workspace. The core Spark engine code cannot be debugged directly from the client.

> [!NOTE]
>
> This feature works with Databricks Runtime 13.3 and above.

To enable the Databricks Connect integration for notebooks in the Databricks IDE extension, you must install Databricks Connect in the Databricks IDE extension. See [Debug code using Databricks Connect for the Databricks IDE extension](https://docs.databricks.com/aws/en/dev-tools/vscode-ext/databricks-connect.md).

## Run Python notebook cells

For notebooks with filenames that have a `.py` extension, when you open the notebook in the Visual Studio Code IDE, each cell displays **Run Cell**, **Run Above**, and **Debug Cell** buttons. As you run a cell, its results are shown in a separate tab in the IDE. As you debug, the cell being debugged displays **Continue**, **Stop**, and **Step Over** buttons. As you debug a cell, you can use Visual Studio Code debugging features such as watching variables' states and viewing the call stack and debug console.

For notebooks with filenames that have a `.ipynb` extension, when you open the notebook in the Visual Studio Code IDE, the notebook and its cells contain additional features. See [Running cells](https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_running-cells) and [Work with code cells in the Notebook Editor](https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_work-with-code-cells-in-the-notebook-editor).

For more information about notebook formats for filenames with the `.py` and `.ipynb` extensions, see [Import and export Databricks notebooks](https://docs.databricks.com/aws/en/notebooks/notebook-export-import.md).

### Run Python Jupyter notebook cells

To run or debug a Python Jupyter notebook (`.ipynb`):

1. In your project, open the Python Jupyter notebook that you want to run or debug. Make sure the Python file is in Jupyter notebook format and has the extension `.ipynb`.

   > [!TIP]
   >
   > You can create a new Python Jupyter notebook by running the **>Create: New Jupyter Notebook** command from within the **Command Palette**.

2. Click **Run All Cells** to run all cells without debugging, **Execute Cell** to run an individual corresponding cell without debugging, or **Run by Line** to run an individual cell line-by-line with limited debugging, with variable values displayed in the **Jupyter** panel (**View > Open View > Jupyter**).

   For full debugging within an individual cell, set breakpoints, and then click **Debug Cell** in the menu next to the cell's **Run** button.

   After you click any of these options, you might be prompted to install missing Python Jupyter notebook package dependencies. Click to install.

   For more information, see [Jupyter Notebooks in VS Code](https://code.visualstudio.com/docs/datascience/jupyter-notebooks).

## Notebook globals

The following notebook globals are also enabled:

* `spark`, representing an instance of `databricks.connect.DatabricksSession`, is preconfigured to instantiate `DatabricksSession` by getting Databricks authentication credentials from the extension. If `DatabricksSession` is already instantiated in a notebook cell's code, this `DatabricksSession` settings are used instead. See [Code examples for Databricks Connect for Python](https://docs.databricks.com/aws/en/dev-tools/databricks-connect/python/examples.md).

* `udf`, preconfigured as an alias for `pyspark.sql.functions.udf`, which is an alias for Python UDFs. See [pyspark.sql.functions.udf](https://docs.databricks.com/aws/en/pyspark/reference/functions/udf.md).

* `sql`, preconfigured as an alias for `spark.sql`. `spark`, as described earlier, represents a preconfigured instance of `databricks.connect.DatabricksSession`. See [Spark SQL](https://docs.databricks.com/aws/en/pyspark/reference/index.md).

* `dbutils`, preconfigured as an instance of Databricks Utilities, which is imported from `databricks-sdk` and is instantiated by getting Databricks authentication credentials from the extension. See [Use Databricks Utilities](https://docs.databricks.com/aws/en/dev-tools/sdk-python.md#use-databricks-utilities).

  > [!NOTE]
  >
  > Only a subset of Databricks Utilities is supported for notebooks with Databricks Connect.
  >
  > To enable `dbutils.widgets`, you must first install the Databricks SDK for Python by running the following command in your local development machine's terminal:
  >
  > ```
  > pip install 'databricks-sdk[notebook]'
  > ```

* `display`, preconfigured as an alias for the Jupyter builtin `IPython.display.display`. See [IPython.display.display](https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display).

* `displayHTML`, preconfigured as an alias for `dbruntime.display.displayHTML`, which is an alias for `display.HTML` from `ipython`. See [IPython.display.html](https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.HTML).

## Notebook magics

The following notebook magics are also enabled:

* `%fs`, which is the same as making `dbutils.fs` calls. See [Mix languages](https://docs.databricks.com/aws/en/notebooks/notebooks-code.md#mix-languages).
* `%sh`, which runs a command by using the cell magic `%%script` on the local machine. This does not run the command in the remote Databricks workspace. See [Mix languages](https://docs.databricks.com/aws/en/notebooks/notebooks-code.md#mix-languages).
* `%md` and `%md-sandbox`, which runs the cell magic `%%markdown`. See [Mix languages](https://docs.databricks.com/aws/en/notebooks/notebooks-code.md#mix-languages).
* `%sql`, which runs `spark.sql`. See [Mix languages](https://docs.databricks.com/aws/en/notebooks/notebooks-code.md#mix-languages).
* `%pip`, which runs `pip install` on the local machine. This does not run `pip install` in the remote Databricks workspace. See [Manage libraries with `%pip` commands](https://docs.databricks.com/aws/en/libraries/notebooks-python-libraries.md#manage-libraries-with-pip-commands).
* `%run`, which runs another notebook. See [Orchestrate Databricks notebooks and modularize code](https://docs.databricks.com/aws/en/notebooks/notebook-workflows.md).

  > [!NOTE]
  >
  > To enable `%run`, you must first install the [nbformat](https://pypi.org/project/nbformat/) library by running the following command in your local development machine's terminal:
  >
  > ```
  > pip install nbformat
  > ```

Additional features that are enabled include:

* Spark DataFrames are converted to pandas DataFrames, which are displayed in Jupyter table format.

## Limitations

Limitations of running cells in notebooks in Visual Studio Code include:

* The notebooks magics `%r` and `%scala` are not supported and display an error if called. See [Mix languages](https://docs.databricks.com/aws/en/notebooks/notebooks-code.md#mix-languages).
* The notebook magic `%sql` does not support some DML commands, such as **Show Tables**.
