---
title: Use the Databricks CLI with AI Runtime
description: Use the Databricks CLI to submit and manage AI Runtime GPU training workloads from your local machine with YAML configurations and MLflow.
canonical_url: https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/
---

# Use the Databricks CLI with AI Runtime

The `databricks air` CLI runs single-node and multi-node GPU workloads on [AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/overview.md), the on-demand serverless GPU compute platform. Define a workload's compute, environment, and command in YAML, then submit it with `databricks air run`.

AI Runtime handles GPU provisioning and environment setup and provides run status, logs, system metrics, and MLflow tracking. The YAML and CLI workflow works naturally with coding agents, which can define, submit, and monitor workloads.

Use the CLI to:

* Develop and iterate on Python applications from your local environment.
* Define repeatable workloads in YAML files that you can source control.
* Submit and manage workloads from a terminal or automated development workflow.

Typical workloads include LLM fine-tuning and post-training, distributed training, batch inference, Ray applications, and hyperparameter search.

For workspace requirements, see [ Requirements](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/overview.md#requirements). To submit a workload, follow the [quickstart](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/quickstart.md).

The Databricks CLI commands for AI Runtime meet the same compliance standards as AI Runtime workloads. For the supported standards and exceptions, see [compliance security profile](https://docs.databricks.com/aws/en/security/privacy/security-profile.md).

> [!NOTE]
>
> The `databricks air` commands and workload configuration differ from the legacy Python-based `air` CLI in the `databricks-air` package. See [Python CLI migration](https://docs.databricks.com/aws/en/dev-tools/cli/reference/air-commands.md#python-cli-migration).

## Explore runnable examples

The [AI Runtime Cookbook](https://github.com/databricks-solutions/ai-runtime-cookbook) contains runnable Databricks CLI workloads for model training, fine-tuning, batch inference, Ray, and hyperparameter search. Each recipe includes a workload YAML file, source code, and instructions for running it.

## <a id="before-running-a-gated-model-recipe" />Before running a gated-model recipe

A Hugging Face token and model approval are separate requirements. Before submitting a workload that uses a gated model:

1. Open the exact model repository named in the recipe, sign in to the Hugging Face account that owns your token, and accept its terms or request access. For example, the [distributed Llama recipe](https://github.com/databricks-solutions/ai-runtime-cookbook/tree/main/language-models/sft-llama-3.1-8b-fsdp-multinode) uses [meta-llama/Llama-3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B). Wait until the repository shows that access is granted. Approval for another Llama model does not grant access to this repository.
2. Create a token that meets the [Hugging Face token requirements](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/environment.md#hugging-face-tokens).
3. Store the token in a Databricks secret in the workspace where you submit the workload, and confirm that the user or service principal authenticated by your CLI profile has `READ` access to the scope. See [Pass credentials to a workload with secrets](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/environment.md#pass-credentials-with-secrets).
4. Before requesting GPUs, verify that the same token can download `config.json` from the exact model repository. In a CPU notebook in the target workspace, install `huggingface_hub`:

   ```python
   %pip install huggingface_hub
   ```

   Run the following Python code in another cell. Replace the scope and key with those in the workload YAML. The notebook identity must have read access to that secret scope:

   ```python
   from huggingface_hub import hf_hub_download

   config_path = hf_hub_download(
       repo_id="meta-llama/Llama-3.1-8B",
       filename="config.json",
       token=dbutils.secrets.get(scope="<scope-name>", key="<key-name>"),
       force_download=True,
   )
   print(f"Downloaded {config_path}")
   ```

   A successful call prints the downloaded file's cache path. `force_download=True` checks access even if the file is cached. The code reads the token from the workspace secret without printing it. For a different recipe, replace `repo_id` with its exact model repository. See the [Hugging Face download guidance](https://huggingface.co/docs/huggingface_hub/guides/download).

For missing secrets, authentication errors, or gated-repository errors, see [Troubleshoot secret and model access](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/environment.md#troubleshoot-secret-access). If a connection failure prevents the download check, access is still unverified. Fix the connection and retry before submitting training.

To start without gated-model approval, choose an ungated recipe from the [AI Runtime Cookbook](https://github.com/databricks-solutions/ai-runtime-cookbook), such as a Qwen recipe. Use that recipe's configuration and dependencies. Replacing the model ID in a Llama recipe can require changes to the training code and GPU sizing.

## How a workload runs

You provide a workload YAML file, application code when needed, and the command that starts your application. When you submit a workload:

1. The workload definition is validated against the supported schema and configuration constraints.
2. If `code_source` is configured, the selected code is packaged as a snapshot and uploaded.
3. The requested GPU compute and environment are prepared on each node.
4. The command provided in the workload YAML runs on each node.

The submission returns a Job Run ID that identifies the workload. Use it to check status, inspect logs and configuration, or cancel the workload. You can also view the Jobs run page and MLflow experiment for execution details, system metrics, logs, and artifacts.

This workflow provides managed GPU provisioning, reproducible environment setup, and built-in observability without requiring you to configure or maintain GPU infrastructure.

## Workload configuration

A workload YAML file describes the following components:

* **Experiment**: The MLflow experiment and run that track the workload.
* **Environment**: The managed environment, dependencies, or [custom Docker image](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/docker-images.md) to use.
* **Compute**: The accelerator type and number of accelerators to provision.
* **Code source**: An optional snapshot of application code to make available to the workload.
* **Command**: The shell command that starts your application.
* **Runtime settings**: Options such as retries, timeouts, environment variables, secrets, and permissions.

For configuration fields and examples, see [Workload YAML reference](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/yaml-config.md).

## Use a custom Docker image

Instead of a managed environment, a workload can run in your own Docker image. Use a custom image when your workload needs system libraries, CUDA extensions, or other dependencies that you can't install with `environment.dependencies`. Custom Docker images are in [Public Preview](https://docs.databricks.com/aws/en/release-notes/release-types.md). To use them, a workspace admin must enable the **Databricks Artifact Registry** preview from the workspace [Previews page](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md#workspace).

You build the image for `linux/amd64`, push it to Artifact Registry in your workspace, and set `environment.unity_catalog_image` in the workload YAML to the image's Unity Catalog name. For the steps, Databricks base images, Docker authentication, and troubleshooting, see [Use custom Docker images with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/docker-images.md).

## Upload application code

Use `code_source` to upload application files with a workload. AI Runtime makes the uploaded directory available on every node and sets `$CODE_SOURCE_PATH` to its location. For example, the following command runs `train.py` from the uploaded directory:

```yaml
command: python "$CODE_SOURCE_PATH/train.py"
```

You can upload the current working tree or select a Git branch or commit. For a complete example, see the [quickstart](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/quickstart.md).

## Develop and manage workloads

Development typically follows this process:

1. Develop the application code and workload YAML locally.
2. Validate the YAML with `databricks air run --file <file> --dry-run`, which checks the configuration against the workspace without submitting a run.
3. Submit the workload with `databricks air run --file <file> --watch` to stream logs until the run finishes.
4. Use `databricks air get`, `databricks air list`, and `databricks air logs` to inspect workloads and logs.
5. Optionally stop a running workload with `databricks air cancel`.

To submit in the background and attach to the logs later, omit `--watch`:

```bash
databricks air run --file workload.yaml
databricks air get <job-run-id>
databricks air logs <job-run-id> --follow
```

The `--follow` flag requires Databricks CLI version 1.27.0 or above. In versions 1.18.0 through 1.26.0, omit it because `databricks air logs` follows an active run by default.

Use the Job Run ID returned by submission. Keep the same workspace profile for all three commands. For default-profile setup and verification, see [Get information about configuration profiles](https://docs.databricks.com/aws/en/dev-tools/cli/profiles.md#using-profiles).

For all commands and flags, see [`air` command group](https://docs.databricks.com/aws/en/dev-tools/cli/reference/air-commands.md).

For scheduled runs, multi-task workflows, or promotion across environments, you can use `databricks air convert-to-dabs` as a starting point for a bundle. See [Schedule GPU workloads and compose tasks](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/monitor-deploy/productionizing-training-workloads.md).

## Track workloads with MLflow

Each submitted workload is represented by a Databricks job run and tracked through an MLflow experiment:

* **Databricks job run**: Shows the workload status, execution attempts, and output on the Jobs run page.
* **MLflow experiment**: Contains the MLflow runs with automatically captured system metrics, workload configuration, and logs. Your application can also use the MLflow APIs to log custom parameters, metrics, and artifacts.

Use the Job Run ID with commands such as `databricks air get`, `databricks air logs`, and `databricks air cancel`. See [Experiment tracking and observability](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/monitor-deploy/tracking-observability.md).

## Run single-node and distributed workloads

AI Runtime runs the configured command one time on each provisioned node. For a distributed workload, it provides coordination variables such as `NUM_NODES`, `NODE_RANK`, `LOCAL_WORLD_SIZE`, `MASTER_ADDR`, and `MASTER_PORT`.

This execution model is framework-independent. Your command must start and configure the distributed framework, for example by invoking `torchrun`, a Ray bootstrap script, or another framework launcher. For complete workloads, see the [AI Runtime Cookbook](https://github.com/databricks-solutions/ai-runtime-cookbook).

## <a id="ai-agent" /> Use an AI agent

The [`databricks-ai-runtime` agent skill](https://github.com/databricks/databricks-agent-skills/tree/main/skills/databricks-ai-runtime) provides instructions that help AI agents, such as Claude Code, Cursor, and Codex, work with AI Runtime through the Databricks CLI. Use it to create workload YAML, submit GPU training jobs, check run status, stream logs, and cancel runs. It also includes guidance for custom Docker images.

After installing the Databricks CLI and configuring authentication, run the following command:

```bash
databricks aitools install --skills-only --skills databricks-ai-runtime
```

Follow the prompts to choose your AI agent and installation scope. In a non-interactive session, such as when an AI agent runs the command, there are no prompts and the skill is installed globally for every detected agent. To choose the agent and scope, pass them as flags. For example, the following command installs the skill for Claude Code in the current project:

```bash
databricks aitools install --skills-only --skills databricks-ai-runtime --agents claude-code --scope project
```

For installation options, see [`aitools` command group](https://docs.databricks.com/aws/en/dev-tools/cli/reference/aitools-commands.md). For what the skill covers, see [Use agent skills with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/coding-agents/agent-skills.md).

## Additional resources

* [Workload YAML reference](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/yaml-config.md)
* [`air` command group](https://docs.databricks.com/aws/en/dev-tools/cli/reference/air-commands.md)
* [Set up your AI Runtime environment](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/environment.md)
* [Use custom Docker images with AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/connecting/cli/docker-images.md)
* [Load data on AI Runtime](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/develop-workloads/dataloading.md)
* [AI Runtime Cookbook](https://github.com/databricks-solutions/ai-runtime-cookbook)
* [AI Runtime examples](https://docs.databricks.com/aws/en/machine-learning/ai-runtime/examples/index.md)
