Repository navigation
Description
Summary
The sandbox variant bind-mounts the whole repository read-write at /workspace, including .git/ and .devcontainer/. Claude Code runs there with permission prompts skipped, so the agent can write files that the host later executes or trusts. The README's stated mitigation is that workspace edits "show in git diff" (claude-code/README.md:354, and :182 for the allowlist). That holds for tracked files, but not for anything under .git/, which git diff never shows.
Paths the sandbox agent can write, and what the host does with them:
| Path | Host effect | Visible in git diff |
|---|---|---|
.git/config (core.fsmonitor, core.hooksPath, core.sshCommand, aliases) |
Runs a command on the host's next git call. core.fsmonitor fires on git status, which VS Code runs by itself. |
No |
.git/hooks/* |
Runs on the host's next commit, checkout, merge or push | No |
.devcontainer/devcontainer.json → initializeCommand |
Runs on the host at the next rebuild or reopen | Yes, if someone looks before rebuilding |
.devcontainer/claude-sandbox/allowed-domains.txt |
The firewall allows the added domains on the next container start | Yes, if someone looks before restarting |
This is the same class as #208 (workspace-writable firewall script), one level out: the firewall itself is now safe, but the host-side trust in the workspace is not.
Reproduction
Not run end to end. It follows from the mount, and each step is ordinary git or devcontainer behaviour.
- Open a project in the sandbox variant.
- In the container:
git config core.fsmonitor 'touch /tmp/pwned-by-sandbox; false'(writes/workspace/.git/config). - On the host, in the same repo:
git status. /tmp/pwned-by-sandboxexists on the host.git diffin the repo shows nothing.
Verification
# the mount
claude-code/.devcontainer/claude-sandbox/docker-compose.yml:12
- ../..:/workspace:cached
# prompts are skipped in the sandbox
claude-code/.devcontainer/claude-sandbox/devcontainer.json:100
"claudeCode.allowDangerouslySkipPermissions": true
# the host runs this from a workspace file
claude-code/.devcontainer/claude-sandbox/devcontainer.json:12
"initializeCommand": "docker pull ghcr.io/gatezh/devcontainers/claude-code-sandbox:latest || exit 0",
# the firewall reads its allowlist from the workspace
claude-code/.devcontainer/init-firewall.sh:14
ALLOWLIST=/workspace/.devcontainer/claude-sandbox/allowed-domains.txt
Suggested fix
Options, none tested:
- Mount
.devcontainerread-only in the sandbox. Add- ../../.devcontainer:/workspace/.devcontainer:roto the sandboxdocker-compose.yml. Closes theinitializeCommandand allowlist rows. Cost: devcontainer config can't be edited from inside the sandbox, which is arguably the point. - Mount
.git/configand.git/hooksread-only in the sandbox. Closes the two rowsgit diffcan't see, and the agent can still commit. Costs:git configandgit remote addfail in the sandbox, and the mount breaks when the workspace is a git worktree, where.gitis a file, not a directory. - Document the gap. Change
README.md:354to say that.git/is shared and not covered bygit diff, and tell users to checkgit config --local --listand.git/hooks/after a sandbox session. Cheapest, but relies on the user.
Option 1 plus option 3 looks like the smallest change that doesn't break worktrees.
Affected files in this repo
claude-code/.devcontainer/claude-sandbox/docker-compose.yml:12claude-code/.devcontainer/claude-sandbox/devcontainer.json:12claude-code/.devcontainer/init-firewall.sh:14claude-code/README.md:182,claude-code/README.md:354
Related
- [BUG] sandbox: NOPASSWD:ALL + workspace-writable firewall script lets the agent disable the firewall #208 (closed): sandbox agent could disable the firewall through a workspace-writable script
- [BUG] default and sandbox variants don't share volumes (Compose project-name prefix) #209 / feat(claude-code): share Bun's store across projects; keep sandbox volumes separate #239: why the variants don't share volumes; the same reasoning applies to
.git/ - Found by an automated security review of a project that adopts the template at
8fe1654
Activity
feat(claude-code): upstream-sync knows the sandbox's read-only .devco…