Dev containers for coding agents: Claude Code, Codex, OpenCode
What a dev container is, running one on a server with the devcontainer CLI, Claude Code's official feature and firewall, Codex and OpenCode, and the limits.
A dev container is a Docker container described by a .devcontainer/devcontainer.json file in your project, under the open Dev Container spec at containers.dev. The file names an image or Dockerfile, the features (packaged install scripts) to add, mounts, environment and setup commands. On a server with no editor, install the Dev Container CLI (npm install -g @devcontainers/cli, version 0.91.0 as of December 2026), then run devcontainer up --workspace-folder . and devcontainer exec --workspace-folder . claude. Anthropic publishes an official Claude Code feature and a reference container with an outbound firewall; OpenAI documents running Codex in a dev container but publishes no feature, and OpenCode documents neither. Mount a named volume over each agent’s config folder so the sign-in survives a rebuild. The container limits what the agent reaches, not what it can steal from inside: both makers warn that credentials in the container are exposed once the approval checks are off.
What a dev container is made of
The Development Container Specification calls itself “an open specification for enriching containers with development specific content and settings.” In practice it is one JSON file the tools agree on. The properties that matter for an agent, from the devcontainer.json reference:
| Property | What it does | Why an agent setup cares |
|---|---|---|
image or build.dockerfile | The base the container starts from | Your toolchain, so the agent can run the tests |
features | Feature IDs and options added to the container | The usual way to install the agent itself |
mounts | Extra mounts, in the syntax of Docker’s --mount | The volume that keeps the agent’s sign-in and history |
containerEnv | Environment variables for the whole container | Pointing the agent at that volume |
remoteUser | The user tools run as inside | Claude Code refuses to skip its checks as root |
runArgs, capAdd | Extra docker run arguments and Linux capabilities | What a firewall inside the container needs, and what quietly widens it |
postCreateCommand, postStartCommand | Commands run once after creation, and on every start | Installing an agent with no feature; starting a firewall |
initializeCommand | A command run on the host during initialization | Read it before opening someone else’s repository |
A feature, per the features spec, is a folder with “at least a devcontainer-feature.json and install.sh entrypoint script”, published to an OCI registry and referenced as <registry>/<namespace>/<feature>:<version>. Its install.sh runs as root while the image is built, so adding a feature is running a stranger’s script as root in your container. That matters for the next section.
Who publishes a feature for which agent
The features index lists every collection someone has registered, and says plainly that “inclusion in this index does not imply that the Dev Container maintainers have security-reviewed or endorsed their code.” Read on December 2, 2026:
- Claude Code has one feature from its maker:
ghcr.io/anthropics/devcontainer-features/claude-code:1.0, listed under the maintainer Anthropic. It has no options; Anthropic’s dev container page says the tag “pins the feature’s install script, not the Claude Code release”, that it installs Node.js itself when the image lacks it, and that it always installs the latest Claude Code. About ten other publishers ship Claude Code features too. - Codex has no feature from OpenAI: no entry in the index’s registry mentions OpenAI. Five community publishers ship one (for example
ghcr.io/sliekens/devcontainer-features/codex:1). - OpenCode has no feature from its makers either, and about nine community ones, among them
ghcr.io/devcontainers-extra/features/opencode:1.
A community feature is a convenience, not a requirement. Each of these agents has an official install command that runs fine as a postCreateCommand, which keeps the install in your own file, uses the maker’s own command, and runs as your user rather than as root.
Running one on a server without VS Code
Editors with dev container support (VS Code, JetBrains IDEs, Cursor, GitHub Codespaces) build and attach for you. On a Linux server over SSH, the Dev Container CLI does the same from a terminal, with Docker already installed. Its npm package needs Node.js 20 or later (and Python and a C compiler to build one dependency); the standalone script brings its own Node.js:
curl -fsSL https://raw.githubusercontent.com/devcontainers/cli/main/scripts/install.sh | sh
export PATH="$HOME/.devcontainers/bin:$PATH"
devcontainer --versionCopiedAdd the export line to your ~/.bashrc to keep it. Then, from the project folder that holds .devcontainer/:
devcontainer up --workspace-folder .
devcontainer exec --workspace-folder . bashCopiedupbuilds the image (features included), creates the container, mounts the project and runs the lifecycle commands. Add--remove-existing-containerafter changingdevcontainer.json, so the old container is removed and a new one made from the changed file.execruns a command in it as theremoteUser, sodevcontainer exec --workspace-folder . claudestarts Claude Code inside. Run it inside tmux on the server and the session survives your SSH connection dropping.devcontainer stopstops the container;devcontainer downstops and deletes it. Named volumes are not containers: Docker’s volumes page says a volume “persists after you delete a container”, which is what keeps the sign-ins below.
A devcontainer.json for Claude Code and Codex
This one starts from Microsoft’s Ubuntu base image, whose vscode user is not root, installs Claude Code with Anthropic’s feature and Codex with OpenAI’s install script, and gives each agent its own volume per project. Save it as .devcontainer/devcontainer.json:
{
"name": "agents",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu24.04",
"features": {
"ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}
},
"remoteUser": "vscode",
"mounts": [
"source=claude-${devcontainerId},target=/home/vscode/.claude,type=volume",
"source=codex-${devcontainerId},target=/home/vscode/.codex,type=volume"
],
"containerEnv": {
"CLAUDE_CONFIG_DIR": "/home/vscode/.claude",
"CODEX_HOME": "/home/vscode/.codex"
},
"postCreateCommand": "sudo chown vscode:vscode /home/vscode/.claude /home/vscode/.codex && curl -fsSL https://chatgpt.com/codex/install.sh | sh"
}Copied${devcontainerId}is unique to each dev container, so two projects never share a sign-in or a history. Drop it to share one volume across projects.- The
chownis there because a named volume mounted at a folder the image does not already have can come up owned by root, and the agent then cannot write its own login. Anthropic’s reference Dockerfile creates and chowns its config folder for the same reason, and community persistence features chown theirs on creation. - Codex’s installer keeps its releases under
CODEX_HOME, so on the volume, linkscodexinto~/.local/binand adds that to~/.bashrc, without sudo. For OpenCode, add&& curl -fsSL https://opencode.ai/v2/install | bashto the same command, with volumes for its two folders in the table below, chowned the same way.
That base image gives vscode sudo access, which is convenient and also means the agent can become root inside the container. For a container you mean as a boundary, build your own image the way Anthropic’s reference does: a non-root user whose sudo rights cover only the firewall script.
Signing in once, and keeping it
Every rebuild throws away the container’s home directory. What each agent needs on a volume:
| Agent | Where its sign-in lives | What to set |
|---|---|---|
Claude Code | ~/.claude (credentials, settings, history) and ~/.claude.json outside it (account, per-project trust, the record that setup is done) | Volume at ~/.claude and CLAUDE_CONFIG_DIR to the same path, so .claude.json lands inside the volume. Without the variable, setup repeats after every rebuild. |
Codex | auth.json in CODEX_HOME (default ~/.codex), a plain-text file, or a system credential store where one is available and Codex is set to use it | Volume at ~/.codex; set CODEX_HOME if you mount it elsewhere |
OpenCode | Its database, ~/.local/share/opencode/opencode.db, which holds saved keys and logins in version 2 (older versions used auth.json beside it), with config in ~/.config/opencode | Volumes at both folders |
There is no browser in the container. Claude Code prints a login URL above its paste prompt: open it on your own computer, sign in, and paste the code it shows back into the terminal. Codex has codex login --device-auth, which per OpenAI’s authentication page has to be enabled first in your ChatGPT security settings (or by a workspace admin). Do either once, through devcontainer exec, and the volume carries it from then on. For unattended use with a token instead of a login, see Claude Code in Docker, which covers passing one without baking it into the image.
Running without approval prompts inside it
This is usually why the container exists. Both makers point the no-prompt modes at a container:
- Claude Code:
claude --dangerously-skip-permissions. Anthropic says to “always run--dangerously-skip-permissionssessions inside a container, a VM, or the sandbox runtime”, and the CLI refuses the flag as root, so set a non-rootremoteUser. Its own Bash sandbox can run inside a container as an extra layer, with the trade-offs in Claude Code’s sandbox. - Codex: OpenAI’s security page has a section on dev containers: “run Codex with Dev Containers and let Docker provide the outer isolation boundary.” Codex’s own sandbox on Linux is bubblewrap plus seccomp, which may not start when the container blocks the namespaces or seccomp operations it needs. Keep it if the container grants what
bwrapneeds; otherwise runcodex --sandbox danger-full-accesswith the container as the boundary. The modes are in Codex’s sandbox.
Both warnings say the same thing. Anthropic: with the checks off, “dev containers do not prevent a malicious project from exfiltrating anything accessible inside the container, including the Claude Code credentials stored in ~/.claude.” OpenAI: “a malicious project can exfiltrate anything available inside the devcontainer, including Codex credentials.” Use it with repositories you trust, mount no ~/.ssh or cloud credential files, and prefer short-lived or repository-scoped tokens. How the no-prompt modes compare with the safer middle settings is in running Claude Code and Codex without permission prompts.
Anthropic’s firewall, read closely
The reference container in anthropics/claude-code/.devcontainer is the only dev container any of these three agents’ makers publishes, and it controls egress. It adds NET_ADMIN and NET_RAW to the container and runs init-firewall.sh as its postStartCommand, on every start. Its default is to drop everything and reject other outbound traffic. What it lets through matters more than the default:
- Every GitHub address range (web, API and git, from
api.github.com/meta), not only your repository. Anthropic’s own sandboxing docs warn that “allowing broad domains such asgithub.comcan create paths for data exfiltration.” - Outbound SSH on port 22 and DNS on UDP port 53 to any address, since neither rule names a destination:
sshor agit pushover SSH reaches any server on the internet. - A whole /24 network, in and out: the script takes the container’s default gateway and allows its /24, which on Docker’s usual bridge network is the host and the other containers on that network.
- Seven named hosts (
registry.npmjs.org,api.anthropic.com,sentry.io,statsig.comand three VS Code hosts), each resolved to its IPv4 addresses once, when the script runs. An address that changes later is blocked until the next start. - Nothing over IPv6 is filtered. Every rule is IPv4
iptables; the script has noip6tablesrules. That matters only if the container’s Docker network has IPv6 turned on, which in Docker is a setting you enable yourself.
claude.ai and platform.claude.com are not on the list, and Anthropic’s network requirements name both for signing in with a Claude account and for refreshing the token. Add them if a subscription login fails behind the firewall. Codex and OpenCode need their own providers’ hosts added the same way. The script also depends on the agent not being able to undo it: the reference gives its user sudo for the firewall script only, while an image whose user has general sudo, plus NET_ADMIN, leaves the rules one command away from the agent.
What a dev container does not do
- It shares the host’s kernel. Anthropic’s comparison of isolation options reserves “the strongest separation” for a virtual machine “with its own kernel”. Where that is the requirement, run the agent in a VM, or on a server that holds nothing else.
- The project is your real files. The workspace is bind-mounted, so every edit, deletion and git hook the agent writes lands on the host. Commit or back up before an unattended run.
- Docker inside defeats it. The official
docker-outside-of-dockerfeature exists to “re-use the host docker socket”, and Anthropic’s docs say access to/var/run/docker.sock“effectively grants access to the host system”. Thedocker-in-dockerfeature avoids the socket by running the container privileged instead. Neither belongs in a container meant to hold an agent with its checks off. - The file is a convention. Anyone who can edit the repository can edit
devcontainer.json, including the agent working in it, and the change takes effect at the next rebuild. Anthropic calls a committed dev container “a convention rather than an enforcement boundary”. A repository you did not write can also carry aninitializeCommand, which runs on the host.