---
title: Set up your AI Runtime environment
description: "AI Runtime offers two managed Python environments: a minimal Standard environment and a Databricks AI environment preloaded with PyTorch and Transformers."
canonical_url: https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/environment
---

# Set up your AI Runtime environment

AI Runtime provides two managed Python environments. The Standard environment includes `cuda`. As of environment version 5, `torch` and `torchvision` are no longer pre-installed. The Databricks AI environment is pre-loaded with PyTorch, Transformers, and other ML and deep learning frameworks. Choose the Standard environment for full control over your dependency stack, or the AI environment for a ready-to-use training setup. You can start from either environment and install more packages yourself.

Key points on this page:

* Choose the **Standard** environment for full control over dependencies, or the **Databricks AI** environment for a ready-to-use ML stack.
* Standard includes `cuda`. As of environment version 5, `torch` and `torchvision` are not pre-installed. The AI environment adds PyTorch, Transformers, and more.
* Install more packages with `%uv pip install` (environment version 5 and above) or `%pip install` in a notebook, or with `environment.dependencies` in the CLI.

## What environment to use

AI Runtime offers two managed Python environments, the Standard environment and the Databricks AI environment. Workloads that you submit with the Databricks CLI can also run in a custom Docker image.

| Environment                                                                                                           | Key characteristics                                                                                                                                                                                                               | When to use                                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| Standard environment                                                                                                  | Minimal; includes `cuda`. As of [environment version 5](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/five-gpu.md#standard-environment), `torch` and `torchvision` are no longer pre-installed. | You want full control over your dependency stack and prefer to install only what you need                                                    |
| Databricks AI environment                                                                                             | Pre-loaded with popular ML frameworks (PyTorch, Transformers, and more)                                                                                                                                                           | You want a complete environment for training, fine-tuning, and experimentation without manual dependency management                          |
| [Custom Docker image](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/docker-images.md) | Your own image stored in Artifact Registry, usually built from a Databricks base image. Available for Databricks CLI workloads.                                                                                                   | You need system libraries, compiled CUDA extensions, or an existing container setup that you can't reproduce with `environment.dependencies` |

You can also use a [workspace base environment](https://docs.databricks.com/aws/en/compute/serverless/dependencies.md#base-environment) that a workspace admin has built for AI Runtime. See [Build for serverless GPU compute (AI Runtime)](https://docs.databricks.com/aws/en/admin/workspace-settings/base-environment.md#build-for-serverless-gpu-compute-ai-runtime).

To choose an environment in a notebook, open the **Environment** side panel and select a [base environment](https://docs.databricks.com/aws/en/compute/serverless/dependencies.md#base-environment):

![Selecting a base environment in the notebook Environment side panel.](https://docs.databricks.com/aws/en/images/machine-learning/ai-runtime/air-notebook-env.gif)

### <a id="standard-env" />Standard environment (minimal environment)

A minimal, stable environment containing only the required packages for AI Runtime operation. The environment includes `cuda` for GPU support. As of environment version 5, `torch` and `torchvision` are no longer pre-installed. Install the versions your workload needs with `%uv pip install` or `%pip install`. For the packages installed in each environment version, see the release notes below.

Best for: Users who want full control over their dependency stack and prefer to install only what they need.

To select: In the **Environment** side panel, choose **Standard v6** as your base environment.

For more details about package versions installed in different versions, see the release notes:

* [GPU environment 6](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/six-gpu.md#standard-environment)
* [GPU environment 5](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/five-gpu.md#standard-environment)
* [GPU environment 4](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/four-gpu.md#standard-environment)

### <a id="ai-env" />Databricks AI environment

Available in environment 4 and later. The AI environment is built on top of the Standard environment with common runtime packages and packages specific to machine learning on GPUs. Pre-installed packages include:

* PyTorch (with CUDA support)
* Transformers (Hugging Face)
* And additional ML/DL dependencies

Best for: ML practitioners who want a complete environment for training workloads, fine-tuning, and experimentation without manual dependency management.

The Databricks AI environment requires a serverless GPU accelerator and cannot be selected for serverless CPU compute; a notebook job task that pairs it with CPU compute is rejected at submit. On serverless CPU compute, the Standard environment does not include PyTorch or the AI Runtime SDK (`databricks.air`), so AI Runtime code must run on a GPU accelerator.

To select: In the **Environment** side panel, choose **AI v6** as your base environment.

For more details about package versions installed in different versions, see the release notes:

* [AI environment 6](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/six-gpu.md#ai-environment)
* [AI environment 5](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/five-gpu.md#ai-environment)
* [AI environment 4](https://docs.databricks.com/aws/en/release-notes/serverless/environment-version/four-gpu.md#ai-environment)

## <a id="install-packages" />Install additional packages

You can start from either a managed environment or a workspace base environment and install your own Python packages on top of it. How you install them depends on how you connect to AI Runtime.

### <a id="install-packages-notebook" />In a notebook

Install packages at the top of your notebook or training script with `%uv pip`, which installs with [uv](https://docs.astral.sh/uv/) and is faster than `%pip`. Pin versions so runs stay reproducible:

```python
%uv pip install "trl==1.1.0"
%uv pip install "transformers==5.5.4"
```

For the full `%pip` and `%uv pip` reference, including which environment versions support each, see [Manage libraries with `%uv` commands](https://docs.databricks.com/aws/en/libraries/notebooks-python-libraries.md#uv-commands).

When you use the `@distributed` decorator for multi-GPU workloads, packages you install before you call `.distributed()` are automatically snapshotted and propagated to all distributed processes. The total size of installed packages must not exceed 15 GB. For more details, see [ Add dependencies to the notebook](https://docs.databricks.com/aws/en/compute/serverless/dependencies.md#add-dependencies).

### <a id="install-packages-cli" />With the CLI

The [`air` CLI](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/index.md) uses the same managed environments. Select one with `environment.version`, then list the packages to install on top of it under `environment.dependencies` in your workload YAML. The CLI installs them into the selected environment with [uv](https://docs.astral.sh/uv/), so you don't manage a separate virtual environment yourself:

```yaml
environment:
  version: '6'
  dependencies:
    - trl==1.1.0
    - transformers==5.5.4
```

The Standard environment doesn't include `torch` or `torchvision`, so if your workload imports them, add them to `dependencies`. To start from the Databricks AI environment instead, which includes PyTorch, set `version` to an AI environment identifier such as `databricks_ai_v6`. For the full dependency format and supported install flags, see [environment](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/yaml-config.md#environment). To run the workload in your own image instead of a managed environment, see [Use custom Docker images with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/docker-images.md).

## <a id="pass-credentials-with-secrets" />Pass credentials to a workload with secrets

Use workspace secrets to pass credentials to workloads submitted with the Databricks CLI. The workload runs as the user or service principal authenticated by the selected CLI profile. The following procedure uses a Hugging Face token as an example. To pass another credential, replace `HF_TOKEN` with the environment variable your application reads. For Hugging Face token requirements, see [Hugging Face tokens](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/environment.md#hugging-face-tokens).

1. Select the workspace where you submit the workload and confirm its host:

   ```bash
   export DATABRICKS_CONFIG_PROFILE=<profile>
   databricks auth describe
   ```

2. Create a [Databricks-backed secret scope](https://docs.databricks.com/aws/en/security/secrets/workspace-secret-scopes.md#databricks-backed), or use an existing scope you can write to. Replace the scope and key placeholders with the names you use in your workload YAML:

   ```bash
   databricks secrets create-scope <scope-name>
   databricks secrets put-secret <scope-name> <key-name>
   ```

   Enter the token at the interactive prompt. Keep the token out of the YAML, command arguments, and source control. If you use an existing scope, skip `create-scope`. Key names can't contain `/`. If the key already exists, `put-secret` overwrites its value.

3. If the authenticated user or service principal doesn't have `READ` access to the scope, ask a user with `MANAGE` permission on the scope to grant access. If you created the scope with the same identity, you already have `MANAGE`, which includes `READ`, and can skip this step. Replace `<principal>` with the authenticated user's email address, service principal's application ID, or group name:

   ```bash
   databricks secrets put-acl <scope-name> <principal> READ
   ```

   Granting permissions on a secret scope requires the [Premium plan or above](https://databricks.com/product/pricing/platform-addons). Scope permissions apply to every secret in the scope. Use a dedicated scope when you need to restrict access. See [secret scope permissions](https://docs.databricks.com/aws/en/security/secrets/workspace-secret-scopes.md#grant-a-user-permissions-on-a-secret-scope).

4. Reference the secret in your workload YAML:

   ```yaml
   secrets:
     HF_TOKEN: <scope-name>/<key-name>
   ```

   AI Runtime resolves the reference and provides the token as the `HF_TOKEN` environment variable to the workload. Setting `HF_TOKEN` in your local shell alone does not configure the remote workload.

5. Verify the key and scope permissions without retrieving or printing the token:

   ```bash
   databricks secrets list-secrets <scope-name>
   databricks secrets list-acls <scope-name>
   ```

   Confirm that the expected key exists and that the authenticated user or service principal has `READ` or a higher permission, directly or through a group. These commands show key metadata and scope permissions. They don't validate the token or model approval. If you can't list scope permissions, ask a user with `MANAGE` permission on the scope to verify access.

Secrets are workspace-scoped. When you change CLI profiles or workspaces, repeat the host, key, and access checks in the destination workspace. The same scope and key names can refer to different secrets in different workspaces.

After you update a secret, a retried workload receives the new value. In notebook code, read the secret again to retrieve its updated value.

For notebook workloads, use `dbutils.secrets.get` to read a workspace secret. For example, to set `HF_TOKEN` in the notebook's Python process:

```python
import os

os.environ["HF_TOKEN"] = dbutils.secrets.get(scope="<scope-name>", key="<key-name>")
```

Don't print the secret. The notebook identity needs `READ` access to the scope. See [get command (dbutils.secrets.get)](https://docs.databricks.com/aws/en/dev-tools/databricks-utils.md#dbutils-secrets-get).

### <a id="hugging-face-tokens" />Hugging Face tokens

Before running a workload that reads a private or gated model, create a [Hugging Face access token](https://huggingface.co/docs/hub/en/security-tokens) with read access to the model repository. For a fine-grained token, grant read access to that repository. The Hugging Face account that owns the token must have access to the model. Creating a token doesn't grant model approval.

The secret mapping in the procedure provides the token as `HF_TOKEN`, which Hugging Face libraries read from the workload environment.

### <a id="troubleshoot-secret-access" />Troubleshoot secret and model access

If the workload fails, find the symptom in the following table:

| Symptom                                                    | Fix                                                                                                                            |
| ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| The workload can't find the scope or key.                  | Confirm that the scope and key in the workload YAML match the ones you created in the workspace where you submit the workload. |
| Secret permission error.                                   | Grant the user or service principal authenticated by the CLI `READ` access to the scope. See the preceding procedure.          |
| Hugging Face rejects the token (401).                      | Check that the token is valid and has read access to the model repository. Replace an expired or revoked token.                |
| `GatedRepoError` or a 403 response for a gated repository. | Confirm that the token owner's access to the model was approved and that the token has read access to that repository.         |

## Workspace base environments

A workspace admin can build a [workspace base environment](https://docs.databricks.com/aws/en/admin/workspace-settings/base-environment.md) for AI Runtime, which makes it available to all users in the workspace through the **Base environment** drop-down menu. For details, see [Build for serverless GPU compute (AI Runtime)](https://docs.databricks.com/aws/en/admin/workspace-settings/base-environment.md#build-for-serverless-gpu-compute-ai-runtime).

To use a base environment in a scheduled workload, reference it by its identifier in the `environments` block of a job or bundle. The Databricks AI environment runs only on GPU compute, so the task must also select a GPU with `hardware_accelerator`. A task that references the AI environment without a `compute` block fails when the run starts. For example, this Declarative Automation Bundles task selects the Databricks AI environment on a single A10 GPU:

```yaml
resources:
  jobs:
    train:
      tasks:
        - task_key: train
          environment_key: default
          compute:
            hardware_accelerator: GPU_1xA10
      environments:
        - environment_key: default
          spec:
            base_environment: databricks_ai_v6
```

For a complete job example, see [Schedule GPU workloads and compose tasks](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/monitor-deploy/productionizing-training-workloads.md).

## <a id="environment-caching-and-custom-modules" />Environment caching and custom modules

### When are environments cached?

AI Runtime caches your notebook's environment, so when you reopen the notebook you don't need to reinstall packages. For details, see [Reset the environment dependencies](https://docs.databricks.com/aws/en/compute/serverless/dependencies.md#reset).

Caching applies to interactive notebooks. Workloads run through the [`air` CLI](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/index.md) or scheduled as jobs don't use this cache; each run installs its dependencies fresh.

As a best practice, pin packages to a specific version so your cached environment stays valid and your runs stay reproducible.

### How do I import custom modules?

The following steps show how to use your own Python modules.

1. **Sync your code to the workspace.** Clone a Git repository into the workspace with a [Git folder](https://docs.databricks.com/aws/en/repos/index.md), or upload the files directly as [workspace files](https://docs.databricks.com/aws/en/files/workspace.md). Store shared code under `/Workspace/Shared` for team projects, or in a user folder for personal development. Keeping the code in a Git folder keeps it version controlled.
2. **Add the folder to `sys.path` and import it** at the top of your notebook or training script:

```python
import sys
sys.path.append("/Workspace/Shared/my-project/src")
from my_module import my_function
```

## Limitations

The following capabilities are not available on AI Runtime:

* **Spark functions**: You cannot import or use PySpark functions directly. AI Runtime is a Python-only environment; Spark is not available as a local runtime. However, Spark Connect is available for data loading. See [Load data on AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/dataloading.md).
* **Databricks Runtime ML libraries**: Pre-installed packages are not a replacement for Databricks Runtime ML. Some ML libraries available in Databricks Runtime ML may not be pre-installed on AI Runtime.
* **Private artifacts**: AI Runtime does support private artifacts in certain cases. Contact your account team for more details.
