---
title: Connect to Databricks using an SSH tunnel
description: Connect Visual Studio Code, Cursor, or your terminal to Databricks serverless or classic compute with the SSH tunnel to run Python and notebooks remotely.
canonical_url: https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel
---

# Connect to Databricks using an SSH tunnel

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md).
>
> Cost and pricing for features in Beta are subject to change.

The Databricks SSH ([Secure Shell](https://en.wikipedia.org/wiki/Secure_Shell)) tunnel connects Visual Studio Code, Cursor, or your terminal to the Databricks workspace and Databricks serverless compute, AI Runtime, or classic compute. Use it to edit workspace files and run or debug Python scripts and notebooks, with your Python environment and code execution on the remote compute. Connect directly to serverless compute, or set up a reusable SSH connection to a dedicated classic cluster.

> [!NOTE]
>
> The SSH tunnel is for IDE-driven and interactive development, including [running Claude Code and Codex](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#coding-agents). To run agent loops or untrusted code in a lightweight, isolated environment, see [Databricks Sandbox](https://docs.databricks.com/aws/en/compute/serverless/sandbox.md). For a comparison of the two, see [IDE connected with SSH](https://docs.databricks.com/aws/en/dev-tools/ide-tools.md#tunnel-vs-sandbox).

## Requirements

Start the SSH connection from your local machine. The tunnel cannot be launched from another remote environment or a Docker container.

To connect to serverless or classic compute, you must have:

* Databricks CLI version 1.5.0 or above installed on your local machine and authentication configured. Check your installed version with `databricks --version`. See [Install or update the Databricks CLI](https://docs.databricks.com/aws/en/dev-tools/cli/install.md).
* Either of the following:
  * Visual Studio Code version 1.110.0 (Universal) or above and the [Remote - SSH extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) (1.0.46+) installed.
  * Cursor version 2.6.11 (Universal) or above.

To connect to serverless compute, port forwarding to serverless compute must be enabled. See [Manage port forwarding to serverless compute](https://docs.databricks.com/aws/en/admin/workspace-settings/port-forwarding-serverless.md).

To connect to serverless GPU compute, the AI Runtime feature must be enabled. See [AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/index.md).

### Additional requirements for classic compute

To connect to classic (dedicated, single-user) compute:

* The compute must be running Databricks Runtime 17.0 or above. See [Dedicated compute overview](https://docs.databricks.com/aws/en/compute/dedicated-overview.md).
* Unity Catalog must be enabled.
* If a compute policy exists, it must not prohibit jobs execution.
* When using [Databricks Container Services for dedicated compute](https://docs.databricks.com/aws/en/compute/custom-containers.md), your Docker image must have `openssh-server` installed.

## <a id="choose-an-ssh-connection" />Choose an SSH connection

Use the connection method for your compute type:

| Compute                                | Connection method                                                                                                                                  | Setup requirement                                                                                                                                                                                                                   |
| -------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Serverless compute                     | `databricks ssh connect`                                                                                                                           | No separate SSH setup step.<br />Add `--ide vscode` or `--ide cursor` to launch an IDE.                                                                                                                                             |
| AI Runtime                             | `databricks ssh connect --accelerator <accelerator>`                                                                                               | No separate SSH setup step.<br />Add `--ide vscode` or `--ide cursor` to launch an IDE.<br />For supported accelerators, see [`--accelerator`](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect). |
| Classic dedicated, single-user compute | Run `databricks ssh setup --name <connection-name>` in your terminal.<br />Then start the SSH session from the IDE or run `ssh <connection-name>`. | Select a dedicated, single-user cluster that meets the classic compute requirements.<br />Shared clusters are not supported.                                                                                                        |

For a comparison with Databricks Connect and other development options, see [Connect from your IDE](https://docs.databricks.com/aws/en/dev-tools/ide-tools.md).

## Connect to serverless compute

Upon meeting the requirements above, run [databricks ssh connect](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect) from your terminal or IDE.

The `--ide` value selects the editor to launch, regardless of which editor or terminal you run the command from.

### Visual Studio Code

```bash
databricks ssh connect --ide vscode
```

The CLI opens a Visual Studio Code window connected to the remote compute.

### Cursor

```bash
databricks ssh connect --ide cursor
```

The CLI opens a Cursor window connected to the remote compute.

### Terminal

```bash
databricks ssh connect
```

The CLI starts an interactive SSH session.

For command options, including named connections and authentication profiles, see [databricks ssh connect](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect).

After connecting, [open your workspace project](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#open) and [select the Python environment](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#run-code). If the connection fails, see [Troubleshoot SSH tunnel connections](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#troubleshooting).

### Connect to serverless GPU compute with AI Runtime

With AI Runtime enabled, add `--accelerator` to use GPU compute:

```bash
databricks ssh connect --accelerator GPU_1xA10
```

`databricks ssh connect` gives you an interactive session on a single node. For long-running training jobs or multi-node distributed training, submit the workload with `databricks air` instead. See [Use the Databricks CLI with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/index.md).

## <a id="connect" />Connect to classic compute

For a reusable connection to a classic dedicated cluster, set up an SSH host name, then select that host in your IDE or connect from a terminal.

### Set up the SSH connection

> [!NOTE]
>
> Setting up the SSH connection is only required if you are connecting to classic compute.

Run [databricks ssh setup](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#setup) on your local machine. Replace `<connection-name>` with a name for this connection, such as `my-connection`:

```bash
databricks ssh setup --name <connection-name>
```

The CLI prompts you to select a cluster and adds a host entry to your SSH configuration. You can also select a cluster directly. Replace `<cluster-id>` with the ID of your dedicated cluster:

```bash
databricks ssh setup --name <connection-name> --cluster <cluster-id>
```

To configure how long the SSH tunnel waits after the last client disconnects, add `--shutdown-delay` to the setup command. The default is 10 minutes. For example, to set a 30-minute delay for connections through this SSH host entry:

```bash
databricks ssh setup --name <connection-name> --cluster <cluster-id> --shutdown-delay 30m
```

> [!NOTE]
>
> For IntelliJ users, Databricks recommends adding `--auto-start-cluster=false` to the setup command and starting the cluster manually before connecting. This is because JetBrains IDEs start all configured clusters on launch, which can result in unexpected compute charges.

### <a id="connect-vscode" />Connect using Visual Studio Code or Cursor

1. For Visual Studio Code, install the [Remote SSH extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh). Cursor includes a remote SSH extension by default.

2. In the IDE main menu, click **View** > **Command Palette**. Select **Remote-SSH: Settings**. Alternatively, select **Preferences: Open User Settings (JSON)** to modify `settings.json` directly.

3. Under **Remote.SSH: Default Extensions** (or `remote.SSH.defaultExtensions` in `settings.json`), add `ms-Python.Python` and `ms-toolsai.jupyter`.

   If you are modifying `settings.json`:

   ```json
   "remote.SSH.defaultExtensions": [
       "ms-Python.Python",
       "ms-toolsai.jupyter"
   ]
   ```

   > [!NOTE]
   >
   > Optionally, increase the value of **Remote.SSH: Connect Timeout** (or `remote.SSH.connectTimeout` in `settings.json`) to further reduce the chance of timeout errors. The default timeout is 360.

4. In the Command Palette, select **Remote-SSH: Connect to Host**.

5. From the drop-down menu, select the connection you set up in the first step. The IDE proceeds to connect in a new window.

### Connect using IntelliJ IDEs

1. Follow the [Remote server tutorial](https://www.jetbrains.com/help/idea/remote-development-starting-page.html) to get set up.
2. On the new connection screen, enter:
   * **Username**: `root`
   * **Host**: `<connection-name>`

### <a id="connect-using-terminal" />Connect to classic compute from a terminal

Use the connection name you configured with `databricks ssh setup`:

```bash
ssh <connection-name>
```

For a direct connection without a reusable SSH host entry, you can also use the CLI. Replace `<cluster-id>` with your dedicated cluster ID:

```bash
databricks ssh connect --cluster <cluster-id>
```

See [databricks ssh connect](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect).

## <a id="open" />Open workspace projects through SSH

By default, the `databricks ssh connect` command opens to an ephemeral directory. To access workspace files, navigate to your workspace directory from the IDE or terminal:

* In Visual Studio Code or Cursor, from the Command Palette (**Cmd/Ctrl+Shift+P**) select **Open Folder** and navigate to `/Workspace/Users/<your-username>`.
* From a terminal window, change your directory: `cd /Workspace/Users/<your-username>`.

> [!NOTE]
>
> Files in `/Workspace`, `/Volumes`, and `/dbfs` persist across cluster restarts. Files in `/home`, `/root`, and other local paths are ephemeral and lost on restart.

## <a id="run-code" />Run Python and notebooks in the SSH session

Select the Python environment provided by your SSH session before running code. For classic compute, this environment includes the built-in Databricks Runtime libraries and [compute-scoped libraries](https://docs.databricks.com/aws/en/libraries/cluster-libraries.md).

1. Open the Command Palette (**Cmd/Ctrl+Shift+P**) and select **Python: Select Interpreter**.

2. Select the `pythonEnv-xxx` virtual environment from the list. If you set up Python dependencies using the `--base-environment` flag, select the longer virtual environment name from the list of options. If the virtual environment does not appear:
   1. Run `echo $DATABRICKS_VIRTUAL_ENV` from a terminal within the IDE.

      Example output: `/local_disk0/.ephemeral_nfs/envs/pythonEnv-xxx/bin/python`

   2. Paste the full output as the interpreter path in the **Python: Select Interpreter** prompt.

3. Open a new terminal and the virtual environment should automatically activate.

4. To run a Jupyter notebook, make sure that the virtual environment is selected as the kernel. Click **Select Kernel** in the upper right of the notebook.

Run and debug Python files and `.ipynb` notebooks using the standard Python and Jupyter extensions.

To use Spark in a Python file on serverless compute, initialize a session explicitly:

```python
from databricks.connect import DatabricksSession
spark = DatabricksSession.builder.serverless().profile("DEFAULT").getOrCreate()
```

## <a id="manage-dependencies" />Manage dependencies for SSH sessions

Choose dependency management for your compute type:

* For serverless compute, use a [workspace base environment](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#workspace-base-environments) with a supported serverless environment version.
* For classic compute, use [cluster libraries](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#cluster-libraries) for dependencies that persist across restarts.
* For dependencies scoped to a project session, use a [setup notebook](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#setup-notebook).

For non-Python packages, see [Non-Python dependencies](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#init-scripts).

### <a id="workspace-base-environments" />Workspace base environments (recommended for serverless and AI Runtime)

> [!NOTE]
>
> This feature requires the **Serverless workspace base environment support in Jobs** preview to be enabled. See [Manage Databricks previews](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md).

Use a [workspace base environment](https://docs.databricks.com/aws/en/admin/workspace-settings/base-environment.md) with serverless environment version 4 or below to pre-configure Python dependencies. The SSH tunnel does not support `--base-environment` with serverless environment version 5 or above. Create a base environment using the [workspace UI](https://docs.databricks.com/aws/en/admin/workspace-settings/base-environment.md#create-base-env) or the Databricks CLI [databricks environments create-workspace-base-environment](https://docs.databricks.com/aws/en/dev-tools/cli/reference/environments-commands.md) command.

Specify the environment using the `--base-environment` option when connecting:

```bash
databricks ssh connect --base-environment my-workspace-env
```

The `--base-environment` option accepts a display name, a workspace YAML path, or a resource ID. You cannot combine it with `--cluster`. See [databricks ssh connect](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect).

### <a id="cluster-libraries" />Cluster libraries (recommended for classic compute)

Install dependencies using the workspace UI under **Compute > Libraries**. These persist across cluster restarts and are available in `pythonEnv-xxx`. See [Cluster libraries](https://docs.databricks.com/aws/en/libraries/cluster-libraries.md).

### <a id="init-scripts" />Non-Python dependencies

To persist non-Python dependencies, use an init script that installs the packages when the compute starts. Optionally, store the packages in a Unity Catalog volume and reference them from the init script. See [What are init scripts?](https://docs.databricks.com/aws/en/init-scripts/index.md).

### <a id="setup-notebook" />Project-specific notebook setup

For project-scoped dependencies, run a notebook containing `%pip install` commands at the start of each session:

```python
# Install from pyproject.toml
%pip install .

# Install from a requirements file
%pip install -r requirements.txt

# Install a wheel from Volumes or Workspace
%pip install /Volumes/catalog/schema/volume/your_library.whl
```

`%pip` commands include Databricks-specific guardrails and propagate dependencies to Spark executor nodes. This enables user-defined functions (UDFs) with custom dependencies.

For more examples, see [Manage libraries with `%pip` commands](https://docs.databricks.com/aws/en/libraries/notebooks-python-libraries.md#pip-commands).

You do not need to rerun the setup notebook if you reconnect before the SSH tunnel shuts down. By default, the tunnel shuts down 10 minutes after the last client disconnects. To change this delay, use `--shutdown-delay` with the command for your connection method:

* For a reusable classic compute connection, set the delay with [databricks ssh setup](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#setup). The generated SSH host entry applies the delay when you connect from your IDE or run `ssh <connection-name>`.
* For a direct CLI connection, set the delay with [databricks ssh connect](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect).

> [!NOTE]
>
> Multiple SSH sessions on the same cluster share one virtual environment.

## <a id="using-git" />Use Git in an SSH session

> [!NOTE]
> **Preview**
>
> This feature is in [Public Preview](https://docs.databricks.com/aws/en/release-notes/release-types.md). Workspace admins can control access to **Git CLI support for Git folders** from the **Previews** page. See [Manage Databricks previews](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md).

You can use the Git CLI in the SSH tunnel with newly created Git folders and the Git credentials you've configured in the Databricks workspace. See [Use Git CLI commands](https://docs.databricks.com/aws/en/repos/git-operations-with-repos.md#use-git-cli).

If the CLI prompts for credentials instead of picking them up automatically, you must connect your Git provider to Databricks. See [Connect your Git provider to Databricks](https://docs.databricks.com/aws/en/repos/get-access-tokens-from-git-provider.md).

## <a id="coding-agents" />Run coding agents in an SSH session

You can run Claude Code and Codex in SSH sessions without any installation or configuration. The agents send model requests through Unity Gateway in your workspace and authenticate with the credentials of your SSH session.

### <a id="requirements-for-coding-agents" />Requirements for coding agents

* Databricks CLI version 1.23.0 or above on your local machine.
* Unity Gateway enabled for your workspace, with access to the models you want to use. See the [coding agent quickstart prerequisites](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-quickstart.md).
* Outbound HTTPS access from the compute to the following hosts. The first launch downloads the agent tooling from them:

  * `github.com` and `nodejs.org`
  * PyPI: `pypi.org` and `files.pythonhosted.org`
  * npm registry: `registry.npmjs.org`

  If the compute image already includes `uv` or `npm`, the launcher skips downloading it.

### Launch a coding agent

1. Connect to your compute. See [Choose an SSH connection](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#choose-an-ssh-connection) for the different ways to connect.

2. In the terminal of the SSH session, run the agent:

   ```bash
   claude
   ```

   or

   ```bash
   codex
   ```

   Any arguments you add are passed to the agent unchanged.

To run an agent without opening an interactive session, pass the agent command after `--`. The remote shell interprets the command, so wrap the whole command in single quotes to keep quoted arguments intact. For example, to run Claude Code in non-interactive mode:

```bash
databricks ssh connect -- 'claude -p "Summarize the notebooks in my workspace home folder"'
```

Commands passed after `--` start in your home directory on the compute, not your workspace home folder.

The first time you run an agent on the compute, the launcher downloads and installs the agent tooling automatically.

### <a id="coding-agent-constraints" />Coding agent constraints

* The agent tooling, conversation history, and agent settings are stored in your home directory on the compute. On serverless compute, this directory is lost when the compute shuts down. On a dedicated cluster, it persists across SSH sessions until the cluster restarts or terminates. To keep your work, store files in `/Workspace` or `/Volumes`. See [Files disappear or environment resets after cluster restart](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#files-disappear).
* If you install `claude` or `codex` on the compute yourself, that installation takes precedence and is not configured for Unity Gateway.

## <a id="keep-detached" />Keep detached processes running

By default, when the SSH tunnel shuts down, it stops every process that the session started, including processes that you detached from the session with `tmux`, `setsid`, or `nohup`. Before it stops them, the tunnel logs a warning with their process IDs in the output of the tunnel's job run. `databricks ssh connect` prints the job run ID when it starts the tunnel.

To keep detached work running after you disconnect, use the `--keep-detached-processes` flag. Set the flag on the connection that starts the tunnel, before you start the work that you want to keep. See [Connections to an existing tunnel](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#keep-detached-mode).

* **Serverless or classic compute**: Pass the flag to [databricks ssh connect](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#connect).
* **Classic compute with a configured SSH host**: Pass the flag to [databricks ssh setup](https://docs.databricks.com/aws/en/dev-tools/cli/reference/ssh-commands.md#setup). The generated SSH host entry applies it each time you connect. Serverless connections don't require setup, so this option applies only to classic compute.

The following example keeps detached processes running on serverless compute:

```bash
databricks ssh connect --keep-detached-processes
```

The following example keeps detached processes running on a dedicated cluster:

```bash
databricks ssh connect --cluster 0123-456789-abcdefgh --keep-detached-processes
```

When you use this flag and the last client disconnects, the tunnel behaves as follows:

* After the `--shutdown-delay` period, the tunnel checks for detached processes. While any are running, the tunnel keeps running instead of shutting down.
* Detached processes keep their access to `/Workspace` and `/Volumes`.
* After the last detached process exits, the tunnel shuts down and its job run ends.

While the tunnel keeps running, you can reconnect to the same compute and reattach to detached work, for example with `tmux attach`. On serverless compute, reconnect with the same connection name. If you omit `--name`, the CLI derives the connection name from your workspace and the `--accelerator` and `--base-environment` flags, so changing either flag starts a separate connection.

### <a id="keep-detached-mode" />Connections to an existing tunnel

The tunnel's mode is fixed when it starts, and later connections handle it as follows:

* If you connect with the flag to a tunnel that started without it, the CLI starts a new tunnel. Processes that you detached in the existing tunnel aren't kept, and they still stop when that tunnel shuts down. On a dedicated cluster, the new tunnel stops the existing one immediately, which ends its open sessions and stops its detached processes.
* If you connect without the flag to a tunnel that started with it, the CLI reuses that tunnel, and the tunnel keeps running while detached processes remain. This also applies to connections from other SSH host entries or IDE sessions to the same compute.

### <a id="keep-detached-limits" />Costs and maximum lifetime

Keep the following in mind:

* While the tunnel keeps running, the compute keeps running and incurs costs. A classic cluster doesn't automatically terminate. An idle `tmux` session counts as a running detached process, so close it when you no longer need it.
* The job run still stops when it reaches the maximum lifetime set by `--server-timeout`, even if detached processes are running. This lifetime counts from when the job run starts, not from when the last client disconnects. After the job run stops, detached processes lose their access to `/Workspace` and `/Volumes`. On serverless compute, the detached processes stop. On classic compute, they can keep running without that access until the cluster terminates. To keep the output of long-running detached work, save it with the Databricks SDK or REST API instead of writing to `/Workspace` or `/Volumes` paths. See [Work with files in Unity Catalog volumes](https://docs.databricks.com/aws/en/volumes/volume-files.md).
* For longer-running work, use [jobs](https://docs.databricks.com/aws/en/jobs/index.md) or [bundles](https://docs.databricks.com/aws/en/dev-tools/bundles/index.md) instead.

## <a id="limitations" />SSH tunnel limitations

The SSH tunnel provided by Databricks has the following limitations:

* Shared clusters are not supported.
* SSH sessions on serverless compute use standard memory (16 GB) and don't support [high memory](https://docs.databricks.com/aws/en/compute/serverless/dependencies.md#high-memory). If your workload needs more memory, [connect to classic compute](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#connect) instead.
* Files edited outside `/Workspace`, `/Volumes`, and `/dbfs` are lost on cluster restart.
* A maximum of 10 SSH connections are allowed per cluster.
* Inactive sessions might drop after 1 hour.
* The SSH tunnel cannot be launched from other remote environments or Docker containers.
* You might encounter performance or connection issues when three or more Jupyter notebooks are open simultaneously.

### <a id="notebook" />Notebook behavior in SSH sessions

There are some differences in notebooks when using the SSH tunnel:

* Python files don’t define any Databricks globals (like `spark` or `dbutils`). You must import them explicitly with `from databricks.sdk.runtime import spark`.
* For ipynb notebooks, these features are available:
  * Databricks globals: `display`, `displayHTML`, `dbutils`, `table`, `sql`, `udf`, `getArgument`, `sc`, `sqlContext`, `spark`
  * `%sql` magic command to execute SQL cells

To work with Python source “notebooks”:

* Search for `jupyter.interactiveWindow.cellMarker.codeRegex` and set it to:

  ```
  ^# COMMAND ----------|^# Databricks notebook source|^(#\\s*%%|#\\s*\\<codecell\\>|#\\s*In\\[\\d*?\\]|#\\s*In\\[ \\])
  ```

* Search for `jupyter.interactiveWindow.cellMarker.default` and set it to:

  ```
  # COMMAND ----------
  ```

## <a id="troubleshooting" />Troubleshoot SSH tunnel connections

Start with the symptom that matches the failure:

| Symptom                                                          | First check                                                                                                                                                                                                                   |
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The SSH connection fails or times out.                           | Check workspace HTTPS and WebSocket access. For classic compute, also check the cluster state and IDE timeout. See [SSH connection fails or times out](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#ssh-fails). |
| The CLI reports that it cannot find `code`.                      | Install the Visual Studio Code shell command in your local `PATH`. See [`code` command not found](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#code-not-found).                                                 |
| CLI authentication fails.                                        | Check the CLI profile and, for classic compute, cluster permissions. See [CLI authentication errors](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#cli-auth).                                                    |
| The CLI reports `invalid_grant` with `Refresh token is invalid`. | Sign in again to the workspace using the same CLI profile, then retry the connection. See [Refresh token is invalid](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#refresh-token).                               |
| Python code or notebooks fail after connecting.                  | Check the selected interpreter or notebook kernel. See [Python code or notebooks fail in the SSH session](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#code-fails).                                             |
| Files disappear after a cluster restart.                         | Check whether the files were stored on an ephemeral local path. See [Files disappear or environment resets after cluster restart](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#files-disappear).                |
| `claude` or `codex` fails to start.                              | Check that Unity Gateway is enabled and that your token and permissions allow access. See [Coding agent fails to start](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#agent-fails).                              |

### <a id="ssh-fails" />SSH connection fails or times out

* For classic compute, verify that the cluster is running in the workspace UI.
* Check that your network, VPN, and firewall allow HTTPS and WebSocket traffic to your workspace domain. The SSH tunnel does not use port 22. It tunnels all traffic over the same HTTPS endpoint as other Databricks CLI commands. See [Configure domain name firewall rules](https://docs.databricks.com/aws/en/resources/firewall-rules.md).
* If a proxy or firewall inspects TLS traffic, check that it allows the WebSocket upgrade request. An intermediary that blocks or strips the upgrade causes the connection to fail or time out. Ask your network administrator to allow WebSocket upgrades to your workspace domain, or to bypass TLS inspection for that domain.
* If you connect through a corporate HTTP proxy, set the `HTTPS_PROXY` environment variable, or `NO_PROXY` to bypass the proxy for your workspace domain. The SSH tunnel uses the same proxy configuration as other Databricks CLI commands. See [Proxy server configuration](https://docs.databricks.com/aws/en/dev-tools/cli/usage.md#proxy-server-configuration).
* Check that your local machine has HTTPS access to `github.com` and `release-assets.githubusercontent.com`.
* Increase the SSH timeout. See [Connect using Visual Studio Code or Cursor](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#connect-vscode).
* For key mismatch errors, delete `~/.databricks/ssh-tunnel-keys` and re-run `databricks ssh setup`.
* For "remote host identification has changed" errors, check the `~/.ssh/known_hosts` file and delete entries related to your cluster.
* SSH sessions might drop after 1 hour and no more than 10 SSH connections can be made to a single cluster. See [SSH tunnel limitations](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#limitations).

### <a id="code-not-found" />`code` command not found

If you see `Error: exec: "code": executable file not found in $PATH`, open the Command Palette (**Cmd/Ctrl+Shift+P**), select **Shell Command: Install 'code' command in PATH**, and restart your IDE or terminal session.

### <a id="cli-auth" />CLI authentication errors

* Sign in to your workspace using [databricks auth login](https://docs.databricks.com/aws/en/dev-tools/cli/reference/auth-commands.md).
* For classic compute, confirm that you have `CAN ATTACH TO` permission on the cluster, or `CAN RESTART` if the cluster isn't running.

### <a id="refresh-token" />Refresh token is invalid

If `databricks ssh connect` fails with `error getting token`, `invalid_grant`, and `Refresh token is invalid`, the authorization server rejected the CLI's saved OAuth refresh token. Sign in again to obtain a new session:

1. Identify the configuration profile for the workspace you want to connect to:

   ```bash
   databricks auth profiles --skip-validate
   ```

2. Sign in again using that profile. Replace `<workspace-url>` with the workspace URL, without the `/oidc/v1/token` path, and `<profile-name>` with the matching profile name:

   ```bash
   databricks auth login --host <workspace-url> --profile <profile-name>
   ```

   Complete the sign-in flow in your browser.

3. Retry the connection with the same profile:

   ```bash
   databricks ssh connect --ide vscode --profile <profile-name>
   ```

   Use `--ide cursor` for Cursor, or omit `--ide` for a terminal session.

If the error persists, check that the failed command targets the same workspace and profile you just signed in to. See [OAuth user-to-machine (U2M) authentication](https://docs.databricks.com/aws/en/dev-tools/cli/authentication.md#u2m-auth).

### <a id="code-fails" />Python code or notebooks fail in the SSH session

* Select the Python environment provided by the SSH session. For a notebook, select that environment as the kernel. See [Run Python and notebooks in the SSH session](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#run-code).
* IPYNB notebooks and `*.py` Databricks notebooks have access to Databricks globals, but Python `*.py` files don’t. See [Notebook behavior in SSH sessions](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#notebook).

### <a id="files-disappear" />Files disappear or environment resets after cluster restart

* Files in `/Workspace`, `/Volumes`, and `/dbfs` mounts persist across cluster restarts. Files in `/home`, `/root`, and other local paths are ephemeral and lost on restart.
* Use cluster library management for persistent dependencies. Automate reinstalls using init scripts if needed. See [What are init scripts?](https://docs.databricks.com/aws/en/init-scripts/index.md).

### <a id="agent-fails" />Coding agent fails to start

When you run `claude` or `codex`, the launcher checks that you can reach Unity Gateway before it downloads the agent tooling. If you don't have access to Unity Gateway, the built-in agents can't run. Match the error message to the cause:

* **Unity Gateway is not enabled on this workspace**: Ask your workspace admin to enable Unity Gateway. See [Prerequisites](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-quickstart.md#prerequisites).
* **Model service access could not be verified**: Check that you meet the [Unity Gateway prerequisites](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-quickstart.md#prerequisites), or ask your workspace admin for access to the models.
* **An installation step fails**, for example `✗ Installing Node.js` followed by `failed to download`: Check that the compute can reach `github.com`, `nodejs.org`, `pypi.org`, `files.pythonhosted.org`, and `registry.npmjs.org` over HTTPS. See [Requirements for coding agents](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#requirements-for-coding-agents).

If `claude` or `codex` is not found, check that your local Databricks CLI is version 1.23.0 or above, then reconnect. See [Requirements for coding agents](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#requirements-for-coding-agents).

### SSH setup fails on Windows (WSL)

Run `databricks ssh setup` directly on Windows, not within WSL. The Windows Visual Studio Code instance cannot find SSH configurations created on the WSL side.

## <a id="faq" />FAQ

### Does serverless compute require SSH setup?

No. After installing and authenticating the Databricks CLI, use `databricks ssh connect` for serverless compute. The `databricks ssh setup` command configures reusable SSH host entries for classic dedicated compute.

### Does the Databricks SSH tunnel require port 22?

No. The SSH tunnel carries traffic over HTTPS to your workspace domain and requires WebSocket support. Your network, VPN, firewall, and proxy must allow that traffic. See [SSH connection fails or times out](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#ssh-fails).

### How is the SSH tunnel different from Databricks Connect?

Databricks Connect allows you to write code using Spark APIs and run them remotely on Databricks compute instead of in the local Spark session. The Databricks Visual Studio Code extension uses Databricks Connect to provide built-in debugging of user code on Databricks.

The SSH tunnel allows you to access the workspace from your IDE and moves your entire development environment onto the compute. Python, the kernel, and code execution run on Databricks with access to the compute resources.

### How is my code and data secured?

SSH traffic is encrypted end-to-end, and code runs on the Databricks compute you connect to. Authentication uses the Databricks CLI and your configured workspace profile. See [What authentication methods are supported?](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#authentication-methods).

### Which IDEs are supported?

Visual Studio Code and Cursor are officially supported. Any IDE with SSH capabilities is compatible, but only VS Code and Cursor are tested.

### Can I use coding agents in an SSH session?

Yes. In an SSH session on serverless compute or a dedicated cluster, run `claude` or `codex`. The agents use Unity Gateway with no extra setup. See [Run coding agents in an SSH session](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#coding-agents).

### Are all Databricks notebook features available from the IDE?

Some features such as `display()`, `dbutils`, and `%sql` are available with limitations or manual setup. See [Notebook behavior in SSH sessions](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#notebook).

### Will my cluster start automatically when I connect using the SSH tunnel?

Yes, but if it takes longer to start the cluster than the connect timeout, the connection attempt will fail. To prevent this, increase the value of **Remote.SSH: Connect Timeout** from the command palette (or `remote.SSH.connectTimeout` in `settings.json`) to further reduce the chance of timeout errors.

### How do I know if my cluster is running?

Navigate to **Compute** in the Databricks workspace UI, and check the status of the cluster. The cluster must show *Running* for SSH connection to work.

### How do I disconnect my SSH/IDE session?

You can disconnect a session by closing your IDE window, using the **Disconnect** option in your IDE, closing your SSH terminal, or running the `exit` command in the terminal.

### How do I stop the cluster and avoid charges when I'm not working?

To stop immediately, terminate the cluster from the workspace UI. Navigate to **Compute** in the Databricks workspace UI, find your cluster, and click **Terminate** or **Stop**.

Set a short **auto-termination** policy on your cluster from the workspace UI. After you disconnect, the SSH tunnel waits for the `shutdown-delay` period (default: 10 minutes), then the cluster's idle timeout applies. If you use `--keep-detached-processes`, the cluster doesn't automatically terminate while detached processes are running. This also applies to connections without the flag that reuse a tunnel started with it. See [Connections to an existing tunnel](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#keep-detached-mode).

### How should I handle persistent dependencies?

Dependencies installed during a session are lost after cluster restart. Use persistent storage (`/Workspace/Users/<your-username>`) for requirements and setup scripts. Use cluster libraries or init scripts for automation.

### <a id="authentication-methods" />What authentication methods are supported?

Authentication uses the Databricks CLI and your `~/.databrickscfg` profiles file. SSH keys are handled by the SSH tunnel.

### Can I connect to external databases or services from the cluster?

Yes, as long as your cluster networking allows outbound connections and you have the necessary libraries.

### Can I use additional IDE extensions?

Most extensions work when installed within your remote SSH session, depending on your IDE and cluster. Visual Studio Code by default doesn’t install local extensions on remote hosts. You can manually install them by opening the extensions panel and enabling your local extensions on the remote host. You can also configure Visual Studio Code to always install certain extensions remotely. See [Connect to Databricks](https://docs.databricks.com/aws/en/dev-tools/ssh-tunnel.md#connect).

### Does the SSH tunnel support Private Link?

Yes, however workspace admins must allowlist URLs of Visual Studio Code and Cursor extension marketplaces. Your local machine must also have the ability to access the internet.
