okayus/okayus-skills/claude-code-docker-sandbox
Claude Code and agent skill by okayus/okayus-skills
- community
Checking that the SKILL.md file is still in the repository.
Set up a Docker Compose-isolated development environment where dependency installs and agent-run code execute behind a default-deny network firewall, never touching the host. Use when you want to run `npm install` / `cargo build` / `cabal build` / `go build`, untrusted dependencies, or Claude Code itself in a container to contain supply-chain attacks — without depending on VS Code. Reuses Anthropic's published devcontainer Dockerfile + init-firewall.sh, driven by a plain docker-compose.yml so any host editor works via bind mount; Rust/Haskell/Go toolchains are opt-in build args on the node:24 (LTS) base. Covers the egress allowlist (fatal vs OPTIONAL non-fatal domains), build-time-vs-runtime network, keeping Claude Code current inside the firewall (native updater's host is blocked — update via npm at start), why the /model picker hides flag-gated models until DISABLE_TELEMETRY is unset, bypassPermissions-by-default (container-scope, not repo-shared), and host-side git hygiene.
Install
npx vskill@latest install okayus/okayus-skills/claude-code-docker-sandboxSKILL.md
The same SKILL.md was published earlier as okayus/okayus-skills/claude-code-docker-sandbox.
Claude Code Docker Sandbox
Get a Node/JS project to the state where `npm install`, build tools, and Claude Code all run inside a container behind a default-deny iptables firewall, while you edit files from your normal host editor and run git on the host.
Why do this: supply-chain attacks execute arbitrary code at dependency-install/build time and at run time — npm postinstall scripts, Rust build.rs, Haskell custom Setup.hs, Go go generate / malicious module code in tests are all the same class of hole. A naked npm install / cargo build / cabal build / go build on the host can read ~/.ssh, ~/.aws/credentials, exfiltrate over the network, or backdoor your shell rc files. This skill confines all of that to a container whose only network egress is an explicit allowlist (the package registry, GitHub, your model API, your deploy target) — everything else is rejected at the OS level.
Languages: the base image is node:24 (current Node LTS) because Claude Code itself is an npm package and needs a Node runtime even in a Rust-, Haskell-, or Go-only project. It must be a Node ≥ 22 line: @anthropic-ai/claude-code@latest now declares engines.node >=22, so an older base like node:20 installs with an EBADENGINE warning and the in-container agent misbehaves — pin the base to the current LTS and bump the major as new LTS lines land. Rust (rustup), Haskell (GHCup), and Go (official tarball) are opt-in `--build-arg` layers on top — see Language toolchains.
This is the non-VS-Code path. Anthropic's official .devcontainer/ reference assumes a VS Code / Dev Containers spec editor. Here the same hardened Dockerfile + init-firewall.sh are driven by a plain docker-compose.yml, so the workflow is docker compose exec dev zsh + any host editor.
When to use this skill
- Starting a new Node/JS/TS project and you do not want
npm installto run on the host - You use nvim / helix / emacs / any non-VS-Code editor and the official dev container flow doesn't fit
- You want to run Claude Code (or another coding agent) with reduced permission friction, knowing an OS-level boundary contains it
- You're spooked by a recent npm compromise and want a repeatable isolation baseline across projects
Do not use this when: you need the full VS Code Dev Containers UX (use the official .devcontainer/ instead), you're on native Windows without WSL2 (the firewall needs Linux netfilter — run inside WSL2 or a Linux VM), or you require kernel-level separation against truly untrusted code (use a VM/microVM instead — a container shares the host kernel).
Threat model & limits (read before relying on it)
- What it stops:
postinstallscripts and run-time code from writing outside the project dir, reading host home/credentials, or reaching non-allowlisted network hosts. Blast radius of a malicious package is the bind-mounted project dir + the allowlisted domains. - What it does NOT stop: data exfiltration through an allowlisted domain (e.g. pushing secrets to a GitHub repo you allowed — the firewall filters by hostname, not by intent), kernel exploits (shared kernel), or anything you mount writable. Keep the allowlist narrow and never mount host secrets (
~/.ssh, cloud cred files) into the container. - git push stays on the host. Don't put git credentials in the container. The agent inside can read
git status/git log(the.gitdir is bind-mounted) but you runcommit/pushfrom the host. This keeps your GitHub token out of the isolation boundary. Two documented ways to let the agent push anyway: credential-free viasandboxed-agent-git-relay(host-side relay + GitHub App), or — accepting a repo-scoped, expiring token inside the boundary —sandboxed-agent-github-token-via-1password(fine-grained PAT resolved from 1Password atdocker compose up, env only, never on disk).
Deliverables (completion criteria)
You're done when:
docker compose up -dstarts the container and the logs containFirewall verification passed - unable to reach https://example.com as expectedfollowed by... able to reach https://api.github.com as expected(they won't be the last lines — the startupnpm i -g/ tooling output comes after).docker compose exec dev sh -c 'curl --connect-timeout 5 -s -o /dev/null -w "%{http_code}" https://example.com'prints000(blocked), and the same againsthttps://registry.npmjs.orgprints200.docker compose exec dev zshdrops you into/workspaceas the non-rootnodeuser, and your project files are visible there (bind mount works).- Inside the container,
claudeauthenticates successfully and/statusshows the model — and survivesdocker compose down && docker compose up -d(auth persisted in theclaude-configvolume). - Host-side edits to project files appear inside the container without a rebuild.
- The first message of a fresh in-container
claudesession already contains the repo'sdocs/status.md(injected by the committed SessionStart hook from `agent-status-hub`) — the agent knows where the project stands without being told.
Setup order
Copy the three template files into your repo, then build and verify. Full commented copies are in references/.
- `.docker/Dockerfile` — copy references/Dockerfile verbatim. It is Anthropic's published devcontainer image (base bumped to
node:24LTS): non-rootnodeuser, dev tools,git-delta, zsh+powerlevel10k,@anthropic-ai/claude-codeinstalled globally, and a passwordless-sudo rule scoped to onlyinit-firewall.sh.
- `.docker/init-firewall.sh` — copy references/init-firewall.sh. Edit the
for domain in ...allowlist (see Tuning the allowlist) to match what your project actually needs. GitHub IP ranges are fetched dynamically; you only list extra domains.
- `docker-compose.yml` — copy references/docker-compose.yml into the repo root. Replace the
<project>placeholder incontainer_name. Adjust the published port (5173= Vite default) to your dev server. For a Rust/Haskell/Go project, setINSTALL_RUST/INSTALL_HASKELL/INSTALL_GOto"true"here and uncomment the matching registry block in step 2 — see Language toolchains.
- Build & start:
``sh docker compose build # 5–10 min first time (apt, zsh-in-docker, claude install) docker compose up -d docker compose logs dev # confirm the two "Firewall verification passed" lines ` If docker compose build fails with dial tcp: lookup production.cloudfront.docker.com ... server misbehaving, that's a transient Docker Hub DNS hiccup — just re-run docker compose build`.
- Authenticate Claude Code inside the container — follow references/authentication.md. The key trap: the OAuth localhost callback can't reach the container, so you copy the URL to a host browser and paste the returned code back at the
Paste code here if promptedprompt.
- Verify against the deliverables above.
- Give the in-container agent its bearings — apply `agent-status-hub` before the first autonomous loop: a hard-capped
docs/status.mdinjected by a SessionStart hook in the committed.claude/settings.json, written back with/handoff, capped in CI. Everything is in the repo (bind-mounted at/workspace), so the container needs no rebuild and no extra mount. This matters more in the sandbox than on the host: the container's auto memory and session transcripts live in theclaude-configvolume and never reach the host, so repo files are the only context both sides share.
Tuning the egress allowlist
init-firewall.sh sets default-deny and only permits: DNS, SSH, localhost, the host /24, dynamically-fetched GitHub ranges, plus the domains you list in the for domain in ... loop. The template ships with:
- `registry.npmjs.org` — required for
npm install. - `api.anthropic.com` — required for Claude Code to reach the model. (Using Bedrock/Vertex/Foundry instead? Swap in that provider's endpoint.)
- Cloudflare entries — only if you deploy to Cloudflare. Drop them otherwise.
- Add the registry of any other package manager (
registry.yarnpkg.com), private registries, or CDN hosts your toolchain fetches from at runtime.
The telemetry-domain DNS trap — and the OPTIONAL list that defuses it. The main loop doesexit 1if any listed domain fails to resolve, and that failure kills the container (the firewall is the entrypoint). Anthropic's reference list includesstatsig.anthropic.com,sentry.io, and VS Code Marketplace domains — andstatsig.anthropic.comdoesn't even exist anymore (no A record), so blindly copying it guarantees the failure path. The template therefore has a second, non-fatal OPTIONAL loop: a failed resolve there logs a WARN and continues. Put nice-to-have egress in it — the real Statsig endpoints (statsig.com,api.statsig.com,featuregates.org,statsigapi.net,prodregistryv2.org— one shared anycast IP) and your production hostname, so the in-container agent can verify its own deploys (curl /health). Keepsentry.ioand VS Code domains out entirely.
The /model picker hides flag-gated models — env is the lever, not egress. The picker's roster is driven by Statsig feature flags. With theCLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1umbrella set, new flag-gated models (e.g. Fable 5) silently never appear, even though--model <id>works (entitlement is server-side). Fix: split the umbrella into its parts — keepDISABLE_AUTOUPDATER=1,DISABLE_FEEDBACK_COMMAND=1,DISABLE_ERROR_REPORTING=1, leaveDISABLE_TELEMETRYunset (the compose template does this). Empirically the flags arrive viaapi.anthropic.com, so the picker works even if Statsig egress stays blocked; the optional Statsig entries just let the telemetry uploads succeed too.
Two robustness fixes are baked into the template (learned from real failures; keep them):- `dig` retry. The embedded Docker DNS can intermittently time out at start — worse when several sandboxes come up at once. A single faileddigwouldexit 1and kill the container, so the resolve loop retries up to 5×. This is the safety net the telemetry-trap note above warns you need.- `curl` retry for the GitHub meta fetch. The same first-query DNS hiccup hitsgh_ranges=$(curl -s https://api.github.com/meta)before the allowlist loop — and thatone has no retry, soset -ekills the container with curl's exit code6right afterFetching GitHub IP ranges...(seen on a firstdocker compose up -d, 2026-08-22). Thetemplate now uses--retry 5 --retry-all-errors --retry-delay 2 … || trueand lets theexisting empty-response check report the failure explicitly.- `ipset add -exist`. Providers like Cloudflare serve many hostnames from a shared anycast IP. The same IP can already be in the set from an earlier domain; without-existthe duplicate add returns non-zero andset -ekills the container mid-config. Corollary: because filtering is IP-based, you cannot allow one anycast hostname while blocking another that resolves to the same IP (e.g.docs.mcp.cloudflare.comvsbindings.mcp.cloudflare.com). Control which servers are used at the app layer (e.g..mcp.json), not the firewall.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/claude-code-docker-sandbox/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/okayus/okayus-skills/claude-code-docker-sandbox)