Devcontainers Explained: One File for Your Team, and the AI Catch
Devcontainers explained: one devcontainer.json file sets up the same dev environment for your whole team, and here is the catch when you let an AI agent run inside it.
We walk through the file key by key (the base image or Dockerfile, features, VS Code extensions, forwardPorts, postCreateCommand), open a repo with Reopen in Container, then look at running an AI agent in one. Anthropic's docs say the agent's commands run inside the container, but the mounted project folder is your real repo, VS Code shares your Git credentials and SSH agent by default, and Anthropic's own warning says that with permission prompts skipped, a dev container does not stop a malicious project from taking what is inside it. We finish with where it hurts (slow mounts on Mac and Windows, Docker Desktop licensing) and a short checklist.
Cheat sheet
Where the file lives
In order of precedence:
.devcontainer/devcontainer.json.devcontainer.jsonat the repo root.devcontainer/FOLDER/devcontainer.json(FOLDER is one level deep)
Pick a base (one of three)
| Base | Keys |
|---|---|
| Prebuilt image | image |
| Your own Dockerfile | build.dockerfile |
| Docker Compose | dockerComposeFile plus service |
The main keys
features: shareable install units pulled from an OCI registry such as ghcr.io. Theirinstall.shruns as root while the image is built, so trust what you add.customizations.vscode.extensions: the VS Code extensions everyone gets (VS Code-specific).forwardPorts: ports that are always forwarded, for example[3000, "db:5432"].postCreateCommand: runs once, when the container is first created.remoteUser: defaults to whatever user the container runs as, often root.
Lifecycle hooks
initializeCommand: runs on the host machine, not in the container.onCreateCommand,updateContentCommand,postCreateCommand: run in sequence, once, when the container is first created.postStartCommand: every time the container starts.postAttachCommand: every time a tool attaches.
Add Claude Code with one Feature line
Under features:
ghcr.io/anthropics/devcontainer-features/claude-code:1.0
The :1.0 tag pins the install script, not the Claude Code version.
Open it in VS Code
- With Docker installed, open the repo and run
Dev Containers: Reopen in Container. - The first build takes a while; any edit to
devcontainer.jsonor the Dockerfile means a rebuild.
The doors to check before an agent runs free
- The workspace is a bind mount of your real repo: the agent can still change or delete any file in it.
- By default VS Code reuses your Git credentials and forwards your SSH agent if one is running.
- Anthropic's reference firewall is optional. Its default policy is DROP for INPUT, FORWARD and OUTPUT (
iptables -P INPUT DROPand its siblings), but still allows GitHub, npm and outbound SSH on port 22. - With
--dangerously-skip-permissions, a dev container does not stop a malicious project from exfiltrating anything inside it, including the credentials in~/.claude. --dangerously-skip-permissionsrefuses to run as root, so use a non-rootremoteUser.- A VM, with its own kernel, is stronger isolation than a dev container.
Safety checklist
- No
~/.sshand no cloud credentials mounted. - Short-lived, repo-scoped tokens.
- Trusted repos only.
Where it hurts
- On Mac and Windows, bind mounts are slower (for example during
yarn install): use a named volume. - Windows container images are not supported.
- On Alpine, some extensions may fail because of glibc dependencies.
- Docker Desktop needs a paid plan at companies with 250 or more employees or $10 million or more in annual revenue.
In this video
- Day one and the project won't run
- What a dev container is
- Walking through devcontainer.json
- Reopen in Container
- Week two: an AI agent without the prompts
- The glass box has doors
- Risky repos and where it hurts
- Docker licensing and the safety checklist
Day one and the project won't run 0:00
Day one at a new job, and the project won't even run. The README wants Node, Python, a database, exact versions. By lunch, you're still installing.
What a dev container is 0:10
A dev container fixes that. The setup is described in one file, checked into the repo: devcontainer.json. It's an open spec, not a VS Code trick. Codespaces, JetBrains and DevPod read the same file.
Walking through devcontainer.json 0:24
Walk the file. First, the base: a ready-made image, your own Dockerfile, or Docker Compose. Next, features: shareable install units pulled from a registry. Even Claude Code goes in as one line. Under customizations, the VS Code extensions everyone gets. And forwardPorts makes the app inside show up on your localhost. Last, postCreateCommand runs once, when the container is first created.
Reopen in Container 0:50
Day one again: with Docker installed, open the repo, choose Reopen in Container, and wait for the first build. Your editor stays on your laptop; the terminal and build tools run inside, with your project folder mounted in. It runs, from the same file as everyone else.
Week two: an AI agent without the prompts 1:07
Week two, you want an AI agent to work without asking before every command. Anthropic's docs say commands Claude runs execute inside the container, not on your machine. In VS Code's beginner video, James Montemagno calls it "a clean separation from your local machine."
The glass box has doors 1:23
But this glass box has a door. Your project folder is your real repo, mounted in, so the agent can still change or delete any file in it. Door two: by default, VS Code reuses your Git credentials and forwards your SSH agent if one is running, so code inside could push as you. Door three is the network. Anthropic's reference firewall is optional: it blocks traffic by default, but still lets GitHub, npm and outbound SSH through.
Anthropic warns that with prompts skipped, the container won't stop a malicious project stealing anything inside, even Claude's own login. Security firm Trail of Bits says: "A container is containment, not a strong security boundary." Anthropic rates a virtual machine stronger.
Risky repos and where it hurts 2:07
A stranger's repo is risky too. Once it's open in a container, its setup scripts run by themselves, and initializeCommand runs on your machine. Where it hurts: on Mac and Windows, mounted folders are slower, so use a named volume. Windows container images aren't supported, and on Alpine some extensions may fail.
Docker licensing and the safety checklist 2:25
At work, Docker Desktop needs a paid plan once your company reaches 250 staff or 10 million dollars in revenue. So give every shared project one. Before an agent runs free, keep SSH keys and cloud credentials out, use short-lived, repo-scoped tokens, and open only repos you trust. A dev container fixes your setup, but it isn't a sealed security wall for your AI agent.
What the sources say
- Dev containers are an open specification that lets you use a container as a full-featured development environment, described by a devcontainer.json file kept with the project. containers.dev
- A devcontainer.json starts from one of three bases: a prebuilt image, a Dockerfile through the build setting, or Docker Compose through the dockerComposeFile and service settings. Dev Container Specification, devcontainer.json metadata reference
- The Dev Container CLI is the reference implementation of the specification, and tools such as GitHub Codespaces, DevPod and Ona, formerly Gitpod, read the same devcontainer.json format. containers.dev
- The onCreateCommand, updateContentCommand and postCreateCommand hooks run in sequence once, when the container is first created, while postStartCommand runs every time the container starts. Dev Container Specification, devcontainer.json metadata reference
- Anthropic says that even inside a dev container, Claude can still modify any file in the bind-mounted workspace, which appears directly on your host machine, and can reach anything the network policy allows. Development containers (Claude Code docs), Choose a sandbox environment (Claude Code docs)
- Anthropic warns that when Claude Code runs with --dangerously-skip-permissions, a dev container does not stop a malicious project from exfiltrating anything inside the container, including the Claude Code credentials in ~/.claude. Anthropic
- By default the VS Code Dev Containers extension reuses your local Git credential helper inside the container and forwards your local SSH agent if one is running, and Trail of Bits notes that a forwarded SSH agent lets code in the container authenticate as you. Microsoft, Trail of Bits
- Anthropic's optional reference firewall sets the default policy to DROP for incoming, forwarded and outgoing traffic, yet it still allows GitHub's published IP ranges and outbound SSH on port 22 to any address. init-firewall.sh in the claude-code repository, Development containers (Claude Code docs)
- On macOS and Windows, containers run in a virtual machine, so bind mounts can be slower for disk-heavy commands such as yarn install, and named volumes improve performance there. Improve disk performance, Developing inside a Container
- Docker Desktop is free for personal use, education, non-commercial open source and businesses with fewer than 250 employees and under $10 million in annual revenue, and professional use in larger organisations needs a paid subscription. Docker
Sources
- Development Containers containers.dev
- Dev Container Specification containers.dev
- devcontainer.json metadata reference containers.dev
- containers.dev
- Supporting tools and services containers.dev
- Developing inside a Container Microsoft
- Improve disk performance Microsoft
- code.visualstudio.com
- Sharing Git credentials with your container Microsoft
- Development containers (Claude Code docs) Anthropic
- Choose a sandbox environment (Claude Code docs) Anthropic
- github.com
- init-firewall.sh in the claude-code repository Anthropic
- claude-code-devcontainer README Trail of Bits
- orca.security
- Docker Desktop license agreement Docker
- youtube.com
- youtube.com
More in Developer tools explained
-
2:42
Git Bisect Explained: Find the Bad Commit in About 10 Checks
Git bisect explained: mark one bad commit and an older good one, and Git's binary search finds which of the last thousand commits broke your code in about ten…
-
2:51
Git Worktree Explained: Run Coding Agents in Parallel (and the Catch)
git worktree explained: one repository, several folders, each with its own branch checked out at once. We follow the example in git's own manual (an urgent fix…