GuidesHosting choices

Claude Code in Docker: dev container, image, sign-in, sandboxes

Run Claude Code in a Docker container: Anthropic's dev container and firewall, your own image with a config volume, signing in with no browser, Docker Sandboxes.

November 23, 2026The Everpod team
The short answer

Claude Code runs in an ordinary Linux container, as a non-root user if you want to skip its permission prompts. Install it in the image with curl -fsSL https://claude.ai/install.sh | bash (after WORKDIR /tmp, or the install can hang), mount a named volume at the user’s ~/.claude and set CLAUDE_CONFIG_DIR to that path, so the sign-in and .claude.json survive a rebuild. Sign in once inside with claude auth login (open the URL on your own computer, paste the code back), or pass CLAUDE_CODE_OAUTH_TOKEN from claude setup-token or ANTHROPIC_API_KEY at run time, never as a build argument or ENV. Anthropic publishes a reference dev container with a default-deny firewall for running with --dangerously-skip-permissions, which the CLI refuses as root. Docker’s own Docker Sandboxes (sbx run claude) runs it in a microVM instead.

Three ways to run it, and who each suits

RouteWhat you getSuits
Anthropic’s reference dev container
A Node 20 image, Claude Code, a per-project config volume, and an iptables firewall that allows a short list of hostsWorking in VS Code or another Dev Containers editor, and running unattended with the permission checks off
Your own image with docker run or Compose
Whatever you put in it; you decide the user, the volume, the network and the credentialA server, CI, or a terminal-only workflow
Docker Sandboxes (sbx)
A microVM per sandbox with its own Docker daemon, Claude Code started with permissions bypassedA laptop or a machine with KVM where you want a VM boundary without building one

If containers themselves are new, what a Docker container is covers images, layers and why a container forgets everything not on a volume, which is the problem most of this page solves.

Anthropic’s reference dev container

The .devcontainer folder in Anthropic’s repository (read at v2.1.331, the release of November 23, 2026) is three files. Anthropic’s dev container page calls it “a working example rather than a maintained base image”: copy it and adjust it.

Two things to know before relying on it. The firewall’s list has no claude.ai or platform.claude.com, and Anthropic’s network requirements say claude.ai account sign-in uses the first and that “OAuth token exchange, refresh, and revocation” go to the second for every account. If signing in with a Claude subscription fails or a login stops refreshing with the firewall up, add those two hosts to the script. And the image is Node 20, while Anthropic’s setup page says the npm package requires Node 22; on older Node, npm prints an EBADENGINE warning and the binary still runs.

To add Claude Code to a dev container you already have, the feature ghcr.io/anthropics/devcontainer-features/claude-code:1.0 installs the latest release (the :1.0 pins the install script, not Claude Code); the config volume is set the same way, as in Claude Code in VS Code.

--dangerously-skip-permissions in a container

Anthropic’s sandbox environments page says to “always run --dangerously-skip-permissions sessions inside a container, a VM, or the sandbox runtime”, and that on Linux and macOS Claude Code “refuses to start with this flag when running as root”. The message, as reported in issue #9184 (Claude Code 2.0.10), is:

--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons
Copied

The fix is a non-root user in the image, which every example on this page has. The container narrows what a bypassed session reaches; it does not protect what is inside it. The dev container page warns that with the flag, a malicious project can exfiltrate “anything accessible inside the container, including the Claude Code credentials stored in ~/.claude”, and that Claude “can still modify any file in the bind-mounted workspace, which appears directly on your host.” Its advice: trusted repositories only, no host secrets such as ~/.ssh or cloud credential files mounted in, short-lived or repository-scoped tokens, and an egress limit like the firewall above. How the flag compares with auto mode is in running Claude Code without permission prompts.

Your own image on a server

Without an editor, a small image does the same job. This one uses the native installer, a user whose UID matches yours on the host (for the bind mount, below), and the config directory Anthropic’s own Dockerfile prepares:

FROM debian:bookworm-slim

RUN apt-get update \
 && apt-get install -y --no-install-recommends ca-certificates curl git bash \
 && rm -rf /var/lib/apt/lists/*

ARG USER_UID=1000
RUN useradd --create-home --uid "$USER_UID" --shell /bin/bash claude \
 && mkdir -p /workspace /home/claude/.claude \
 && chown claude:claude /workspace /home/claude/.claude

COPY claude-entrypoint /usr/local/bin/claude-entrypoint
RUN chmod 755 /usr/local/bin/claude-entrypoint

USER claude
WORKDIR /tmp
ARG CLAUDE_CODE_VERSION=stable
RUN curl -fsSL https://claude.ai/install.sh | bash -s "$CLAUDE_CODE_VERSION"

ENV PATH="/home/claude/.local/bin:${PATH}" \
    CLAUDE_CONFIG_DIR=/home/claude/.claude \
    DISABLE_AUTOUPDATER=1
WORKDIR /workspace
ENTRYPOINT ["/usr/local/bin/claude-entrypoint"]
Copied

The entrypoint reads a token from a secret file if one is mounted, then starts Claude Code with whatever arguments you pass:

#!/bin/sh
set -e
if [ -r /run/secrets/claude_oauth_token ]; then
  CLAUDE_CODE_OAUTH_TOKEN="$(cat /run/secrets/claude_oauth_token)"
  export CLAUDE_CODE_OAUTH_TOKEN
fi
exec claude "$@"
Copied

Build it with your UID, then run it in a project with a named volume for the config:

docker build --build-arg USER_UID=$(id -u) -t claude-code .

docker run -it --rm \
  -v "$PWD":/workspace \
  -v claude-config:/home/claude/.claude \
  claude-code
Copied

Arguments after the image name go to claude: ending the command with claude-code auth login signs in, and with claude-code -p "run the tests" runs one prompt and exits.

Signing in with no browser in the container

There are three ways. If more than one is present, the API key wins over the token, and both win over a stored login:

Keeping the credential out of the image

Docker’s build secrets page is plain about it: “Build arguments and environment variables are inappropriate for passing secrets” because “they persist in the final image.” No ARG or ENV with a token or key, and no COPY of one. Give it at run time instead. The short way passes a variable by name only, and Docker copies its value from your shell, where it is already exported, so it never appears in the command:

read -rs CLAUDE_CODE_OAUTH_TOKEN   # paste the token, press Enter; nothing is shown or kept in history
export CLAUDE_CODE_OAUTH_TOKEN

docker run -it --rm -e CLAUDE_CODE_OAUTH_TOKEN \
  -v "$PWD":/workspace -v claude-config:/home/claude/.claude claude-code
Copied

With Compose, a secret is mounted as a file at /run/secrets/<name>, which the entrypoint above reads; Docker’s secrets page notes that environment variables in a Compose file “are often available to all processes” and can end up in logs:

services:
  claude:
    build:
      context: .
      args:
        USER_UID: "1000"   # your id -u
    stdin_open: true
    tty: true
    volumes:
      - ./:/workspace
      - claude-config:/home/claude/.claude
    secrets:
      - claude_oauth_token

volumes:
  claude-config:

secrets:
  claude_oauth_token:
    file: ${HOME}/.config/claude-docker/oauth_token
Copied

Start a session with docker compose run --rm claude, or a one-off prompt with docker compose run --rm claude -p "…". Use run rather than exec into a running container: the token is set by the entrypoint, and a process started with exec does not go through it. Create the token file so the token never passes through your shell history: mkdir -p ~/.config/claude-docker && (umask 077; cat > ~/.config/claude-docker/oauth_token), then paste the token, press Enter and Ctrl+D. It sits outside the project, at mode 600, so it is neither in the bind-mounted workspace nor anywhere git could pick it up; the user built with your UID can still read it. Inside the container the token is readable by anything Claude runs, which is the dev container page’s warning again.

Docker Sandboxes: sbx run claude

Anthropic’s sandbox page lists Docker Sandboxes under virtual machines: “a microVM with its own Docker daemon and workspace sync”, “a free, standalone product from Docker that does not require Docker Desktop.” Docker’s own overview narrows that: the sbx CLI and local sandboxes are free, including for commercial work, while its cloud sandboxes are billed pay-as-you-go. Per Docker’s install page (November 2026), local sandboxes need macOS 14 on Apple silicon, Windows 11 with Windows Hypervisor Platform, or Ubuntu 24.04 or later with KVM, and inside a VM, nested virtualization. On Ubuntu:

curl -fsSL https://get.docker.com | sudo REPO_ONLY=1 sh
sudo apt install docker-sbx
sbx login
sbx run claude ~/my-project
Copied

Per Docker’s Claude Code page, with no extra arguments the sandbox runs claude --dangerously-skip-permissions. Store an API key with sbx secret set anthropic; without one, use /login inside Claude Code for a subscription. Your own ~/.claude is not carried in (“Sandboxes don’t pick up user-level configuration from your host”), only the project’s, and conversations survive removing a sandbox only if you add its session mixin when creating it. The base image is docker/sandbox-templates:claude-code, which you can build on. sbx login signs in to Docker in a browser.

What breaks

On a server, the container sits inside a machine you also have to look after; Claude Code on Linux covers installing it on the host itself when a container is more than you need.

Run Claude Code on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.