> AI agents: For documentation discovery and navigation, see [llms.txt](/llms.txt).

# Work with agents in Dev Containers

Use a Dev Container in the [Agents window](/docs/agents/run/agents-window.md) to run an agent with tools and dependencies inside a container rather than directly on its host. Containers can run on this computer or on a configured SSH, Tunnel, or WSL host. These workflows aren't supported in Visual Studio Code for the Web.

Choose the starting point that fits your task:

* [Use your project's Dev Container](#use-your-projects-dev-container) to work with its existing files and configuration.
* [Create a container without a project](#create-a-container-without-a-project-experimental) for a fresh Ubuntu workspace.
* [Ask the agent to continue in a new container](#ask-the-agent-to-continue-in-a-new-container-experimental) to hand off a task to a new session.

## Choose a container engine (Experimental)

On Windows, use [WSL containers](https://learn.microsoft.com/windows/wsl/wsl-container) instead of Docker to run Dev Containers in the Agents window. WSL containers are part of Windows Subsystem for Linux (WSL). Their `wslc` CLI runs Linux containers without requiring Docker Desktop.

Install **one** of the following container engines on the host that runs the container, with its CLI on `PATH`. Docker isn't required when you use WSL containers (`wslc`).

* [Install and run Docker](/docs/devcontainers/containers.md#installation).
* On Windows, use WSL 2.9.3 or later, which includes `wslc`.

Choose the engine for new containers with `setting(chat.agentHost.devContainer.containerEngine)`:

* `docker` (default): Prefer Docker.
* `wslc`: Prefer WSL containers on Windows.
* `ask`: Prompt you to choose when you create a container interactively and both engines are available.

If the preferred engine isn't available on the host, the other available engine is used. Existing containers keep their engine, so changing the setting doesn't migrate them or prompt you to choose again when you reconnect.

WSL containers run on Windows hosts. A WSL distribution used as a remote host is a Linux host and still requires Docker.

> [!IMPORTANT]
> Terminal sandboxing isn't supported inside WSL containers. If your task requires [sandboxing in Dev Containers](/docs/agents/run/agent-sandboxing.md#use-sandboxing-in-dev-containers), use Docker.

## Use your project's Dev Container

Before starting:

* [Set up a container engine](#choose-a-container-engine-experimental) on the host that contains the folder.
* Add a [Dev Container configuration](/docs/devcontainers/create-dev-container.md) at `.devcontainer/devcontainer.json` or `.devcontainer.json`.
* For remote folders, [configure the connection](/docs/agents/run/remote-agent-sessions.md) to a host that supports Dev Container sessions.

1. Select **New Session** in the Agents window.
1. In the workspace picker, expand the eligible folder's menu and select **Use Dev Container**. The workspace label gains the **- Dev Container** suffix.
1. Choose an available harness and submit your prompt.

To switch back before starting, select **Use This Computer** or **Use Remote Host** from the folder menu. Dev Container sessions edit the container workspace directly and don't support **New Worktree**. For command restrictions, see [sandboxing in Dev Containers](/docs/agents/run/agent-sandboxing.md#use-sandboxing-in-dev-containers).

If startup fails, check the workspace-specific **Dev Container** Output channel. The picker option isn't available for unsupported hosts or folders nested inside another remote environment. Dev Container support is on by default through `setting(chat.agentHost.devContainer.enabled)`.

Idle containers stop after five minutes when no session is working, waiting for input, or holding an unsent draft. Continuing a session restarts the container without losing the conversation. Change the timeout with `setting(chat.agentHost.devContainer.idleTimeout)` (`300` seconds by default, `0` to turn off automatic shutdown). Marking sessions as done or deleting them can still remove the container.

Restarting an existing container is different from rebuilding or replacing it. To keep container-stored chat sessions across replacements, enable `setting(chat.agentHost.devContainer.stateVolume.enabled)` before creating the container. See [Preserve chat sessions across rebuilds](/docs/devcontainers/create-dev-container.md#preserve-chat-sessions-across-rebuilds) `feature(dev-container-state-volume)`, especially the warning about the first rebuild of an existing container.

### Continue chats from Dev Container editor windows

To continue a supported chat that you started in an editor window opened with **Dev Containers: Reopen in Container**, select **Open in Agents Window** from the Chat view **...** menu. The Agents window connects to the running container and opens that chat. This works for folders on this computer or on a connected SSH, Tunnel, or WSL host that use the folder's default Dev Container configuration. Containers without a source folder (such as volume or cloned repository containers) aren't supported, and containers using another configuration file or Docker host open the source folder instead.

To discover and list chats from running folder Dev Containers automatically in the Agents window, enable the experimental `setting(chat.agentHost.devContainer.discovery.enabled)` setting (off by default, requires `setting(chat.agentHost.devContainer.enabled)` and `setting(chat.remoteAgentHostsEnabled)`):

* Running folder Dev Containers on this computer and on connected SSH, Tunnel, or WSL hosts appear in the **Dev Containers** group of **Manage Remote Environments**. For a remote host, connect to that host first.
* Running containers for folders you already trust connect automatically so their chats appear in the sessions list. Discovery never starts a stopped container.
* If you disconnect a container, it stays disconnected across refreshes until you select **Connect** (which prompts for folder trust if needed) or the container stops.
* Only containers using the folder's default Dev Container configuration are discovered.

## Create a container without a project (Experimental)

Create a standalone Ubuntu container when you need a fresh workspace without an existing project folder or `devcontainer.json`. Its files stay in a container volume on the machine that runs the container.

Before starting, [set up a container engine](#choose-a-container-engine-experimental) on the intended host. For a remote host, [connect to it](/docs/agents/run/remote-agent-sessions.md) first.

Enable `setting(chat.agentHost.devContainer.environments.enabled)`, which is off by default. Keep `setting(chat.agentHost.devContainer.enabled)` and `setting(chat.remoteAgentHostsEnabled)` enabled.

1. Run **Agents: Manage Remote Environments** from the Command Palette (`kb(workbench.action.showCommands)`).
1. In the search box's **Filter** menu, choose **Group By > Type** to show the **Dev Containers** group.
1. Select **Create Dev Container** on the **Dev Containers** group. If prompted, choose **This Computer** or a connected host.

    To create the container on a specific connected host, you can instead use the create action on that host's row.

1. After the container connects, select **New Session** and choose it in the **Environment** picker.
1. Choose an available harness and submit your prompt.

Standalone containers persist independently of their sessions. The idle timeout and session cleanup described for project-configured containers don't apply. Disconnecting or marking a session as done doesn't delete the container's files.

> [!CAUTION]
> To remove a standalone container, use **Delete** on its row in **Remote Environments**. This deletes the container and its volumes, including workspace files. Save any work you need elsewhere first. Sessions that ran in the deleted container can no longer continue.

For a container that uses Docker, select **Open in Editor** to edit or debug the workspace in the main editor window and continue a supported session. This requires the Dev Containers extension pre-release, version 0.478.0 or later. For a container on WSL, **Open in Editor** is available only when this computer's Docker engine can access the environment's volume, such as with a shared Docker Desktop engine. A separate Docker engine running only inside WSL isn't supported.

## Ask the agent to continue in a new container (Experimental)

To let an agent create a standalone container and continue work there, [enable standalone containers](#create-a-container-without-a-project-experimental) and turn on `setting(chat.agentHost.devContainer.handoff.enabled)`, which is off by default. This also provides the remote session tools. You don't need to separately enable `setting(chat.remoteSessions.tools.enabled)`.

In an [Agent Host-backed session](/docs/agents/concepts/agent-host.md), describe the task and where the container should run. For example:

```prompt
Create a Dev Container on this computer for a Python command-line tool,
then continue implementing the tool in a new session there.
```

Review the container host and the **Create Remote Session** approval before proceeding. The approval shows the model and reasoning effort that the new session inherits from the current chat. By default, the agent creates the container on the current session's host when it supports containers, otherwise on this computer. Name a connected host in your request when its location matters.

The agent starts a new session in the container and links to it from the original conversation. Unless you ask for a different model, the new session inherits the current chat's model and model options (such as reasoning effort and context window) when the target agent offers that model, and otherwise falls back to the host default. It also inherits the current chat's permissions and mode where supported, falling back to default permissions and interactive mode instead of remembered new-session selections. The agent passes a task summary rather than the full conversation history and doesn't copy the original project's files into the new workspace. The container appears in **Remote Environments** and follows the same persistence and deletion rules as a manually created standalone container.

## Git configuration and credentials

By default, Dev Container sessions in the Agents window without terminal sandboxing receive your Git setup from the computer running the client, similar to [sharing Git credentials in the Dev Containers extension](/remote/advancedcontainers/sharing-git-credentials.md):

* The Agent Host copies your Git configuration when the container doesn't already have its own, and removes unavailable local editors, credential helpers, or signing programs automatically.
* The Agent Host forwards your Git credentials, SSH agent, and GPG agent to processes it starts so `git push`, private HTTPS or SSH operations, and signed commits work without re-authenticating inside the container.
* For Dev Containers running on an SSH, Tunnel, or WSL host, the Git identity, configuration, and credentials come from the computer running the client rather than the remote container host.

The Agent Host doesn't forward Docker credentials, displays, or ports.

To disable Git configuration, credential, SSH agent, and GPG agent forwarding for unsandboxed Dev Containers, turn off `setting(chat.agentHost.devContainer.credentialForwarding.enabled)` (Experimental, on by default). When this setting is off, Dev Container sessions receive only your Git `user.name` and `user.email`. Turning the setting off closes active forwarded connections immediately, and turning it back on takes effect the next time a Dev Container connects.

> [!NOTE]
> Sessions with [terminal sandboxing](/docs/agents/run/agent-sandboxing.md#use-sandboxing-in-dev-containers) receive only your Git `user.name` and `user.email`. Because all sessions in a container share its Agent Host environment, turning sandboxing on for any session in that container withholds Git credentials, SSH agent, and GPG agent forwarding from all sessions on that host.

## Related resources

* [Use the Agents window](/docs/agents/run/agents-window.md)
* [Run and manage remote agent sessions](/docs/agents/run/remote-agent-sessions.md)
* [Configure agent sandboxing](/docs/agents/run/agent-sandboxing.md#use-sandboxing-in-dev-containers)
