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 to work with its existing files and configuration.
- Create a container without a project for a fresh Ubuntu workspace.
- Ask the agent to continue in a new container to hand off a task to a new session.
Choose a container engine (Experimental)
On Windows, use WSL containers 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.
- On Windows, use WSL 2.9.3 or later, which includes
wslc.
Choose the engine for new containers with 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.
Terminal sandboxing isn't supported inside WSL containers. If your task requires sandboxing in Dev Containers, use Docker.
Use your project's Dev Container
Before starting:
- Set up a container engine on the host that contains the folder.
- Add a Dev Container configuration at
.devcontainer/devcontainer.jsonor.devcontainer.json. - For remote folders, configure the connection to a host that supports Dev Container sessions.
- Select New Session in the Agents window.
- In the workspace picker, expand the eligible folder's menu and select Use Dev Container. The workspace label gains the - Dev Container suffix.
- 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 .
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
(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 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.
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 chat.agentHost.devContainer.discovery.enabled setting (off by default, requires chat.agentHost.devContainer.enabled and 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 on the intended host. For a remote host, connect to it first.
Enable chat.agentHost.devContainer.environments.enabled , which is off by default. Keep chat.agentHost.devContainer.enabled and chat.remoteAgentHostsEnabled enabled.
-
Run Agents: Manage Remote Environments from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).
-
In the search box's Filter menu, choose Group By > Type to show the Dev Containers group.
-
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.
-
After the container connects, select New Session and choose it in the Environment picker.
-
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.
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 and turn on chat.agentHost.devContainer.handoff.enabled , which is off by default. This also provides the remote session tools. You don't need to separately enable chat.remoteSessions.tools.enabled .
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 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:
- 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
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.
Sessions with terminal sandboxing 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.