Skip to content

Dev environments

Before scheduling a task or deploying a model, you may want to run code interactively. Dev environments allow you to provision a remote machine set up with your code and favorite IDE with just one command.

Configuration

First, create a YAML file in your project folder. Its name must end with .dstack.yml (e.g. .dstack.yml or dev.dstack.yml are both acceptable).

type: dev-environment

# Specify the Python version, or your Docker image
python: "3.11"

# This pre-configures the IDE with required extensions
ide: vscode

# Specify GPU, disk, and other resource requirements
resources:
  gpu: 80GB

See the .dstack.yml reference for more details.

If you don't specify your Docker image, dstack uses the base image (pre-configured with Python, Conda, and essential CUDA drivers).

Environment variables

Environment variables can be set either within the configuration file or passed via the CLI.

type: dev-environment

env:
  - HUGGING_FACE_HUB_TOKEN
  - HF_HUB_ENABLE_HF_TRANSFER=1

python: "3.11"
ide: vscode

resources:
  gpu: 80GB

If you don't assign a value to an environment variable (see HUGGING_FACE_HUB_TOKEN above), dstack will require the value to be passed via the CLI or set in the current process.

For instance, you can define environment variables in a .env file and utilize tools like direnv.

Profiles

In case you'd like to reuse certain parameters (such as spot policy, retry and max duration, max price, regions, instance types, etc.) across runs, you can define them via .dstack/profiles.yml.

Running

To run a configuration, use the dstack run command followed by the working directory path, configuration file path, and other options.

$ dstack run . -f .dstack.yml

 BACKEND     REGION         RESOURCES                     SPOT  PRICE
 tensordock  unitedkingdom  10xCPU, 80GB, 1xA100 (80GB)   no    $1.595
 azure       westus3        24xCPU, 220GB, 1xA100 (80GB)  no    $3.673
 azure       westus2        24xCPU, 220GB, 1xA100 (80GB)  no    $3.673

Continue? [y/n]: y

Provisioning `fast-moth-1`...
---> 100%

To open in VS Code Desktop, use this link:
  vscode://vscode-remote/ssh-remote+fast-moth-1/workflow

When dstack provisions the dev environment, it uses the current folder contents.

.gitignore

If there are large files or folders you'd like to avoid uploading, you can list them in .gitignore.

The dstack run command allows specifying many things, including spot policy, retry and max duration, max price, regions, instance types, and much more.

VS Code

To open the dev environment in your desktop IDE, use the link from the output (such as vscode://vscode-remote/ssh-remote+fast-moth-1/workflow).

SSH

Alternatively, while the CLI is attached to the run, you can connect to the dev environment via SSH:

$ ssh fast-moth-1

Managing runs

Stopping runs

Once the run exceeds the max duration, or when you use dstack stop, the dev environment and its cloud resources are deleted.

Listing runs

The dstack ps command lists all running runs and their status.

What's next?

  1. Check the .dstack.yml reference for more details and examples