Work with agents in Dev Containers

Use a Dev Container in the Agents window 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

Before starting:

  1. Select New Session in the Agents window.
  2. In the workspace picker, expand the eligible folder's menu and select Use Dev Container. The workspace label gains the - Dev Container suffix.
  3. 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.

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 chat.agentHost.devContainer.enabled Open in VS Code Open in VS Code Insiders .

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 chat.agentHost.devContainer.idleTimeout Open in VS Code Open in VS Code Insiders (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 chat.agentHost.devContainer.stateVolume.enabled Open in VS Code Open in VS Code Insiders before creating the container. See Preserve chat sessions across rebuilds Dev Container state volumes is experimental and might change or be removed. , especially the warning about the first rebuild of an existing container.

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 Docker volume on the machine that runs the container.

Before starting, install and run Docker on the intended host, with its CLI on PATH. For a remote host, connect to it first. For WSL, Docker must be available inside the distribution.

Enable chat.agentHost.devContainer.environments.enabled Open in VS Code Open in VS Code Insiders , which is off by default. Keep chat.agentHost.devContainer.enabled Open in VS Code Open in VS Code Insiders and chat.remoteAgentHostsEnabled Open in VS Code Open in VS Code Insiders enabled.

  1. Run Agents: Manage Remote Environments from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

  2. In the search box's Filter menu, choose Group By > Type to show the Dev Containers group.

  3. 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.

  4. After the container connects, select New Session and choose it in the Environment picker.

  5. 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 Docker volumes, including workspace files. Save any work you need elsewhere first. Sessions that ran in the deleted container can no longer continue.

To edit or debug the workspace in the main editor window, select Open in Editor to open the container workspace 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 and turn on chat.agentHost.devContainer.handoff.enabled Open in VS Code Open in VS Code Insiders , which is off by default. This also provides the remote session tools. You don't need to separately enable chat.remoteSessions.tools.enabled Open in VS Code Open in VS Code Insiders .

In an Agent Host-backed session, describe the task and where the container should run. For example:

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 new-session approval before proceeding. 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. It passes a task summary, not 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.