Skip to content

fix(claude-code): mount .devcontainer read-only in the sandbox - #319

Open
gatezh wants to merge 4 commits into
claude-code/safe-directory-worktreesfrom
claude-code/sandbox-readonly-devcontainer
Open

gatezh wants to merge 4 commits into
claude-code/safe-directory-worktreesfrom
claude-code/sandbox-readonly-devcontainer

Conversation

@gatezh

@gatezh gatezh commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

What

Mounts the project's .devcontainer/ read-only in the sandbox variant, and documents the host-executed files the sandbox can still write (.git/config, .git/hooks/, ignored files) and how to check them.

Why

The sandbox bind-mounts the repository read-write, and Claude Code runs there with permission prompts skipped. The agent could edit .devcontainer/: the host runs initializeCommand from it at the next start, and the firewall reads allowed-domains.txt from it. Both take effect before anyone reviews git diff. .git/ is worse, because git diff never shows it (#289).

Changes

  • claude-sandbox/docker-compose.yml: adds ../../.devcontainer:/workspace/.devcontainer:ro on top of the /workspace bind.
  • README, new section "Host files the sandbox can write" (under Volumes): what the read-only mount covers, what it costs git in the sandbox, what stays open (.git/config, .git/hooks/, ignored files like .claude/settings.local.json, and files hidden through .git/info/exclude), why git can't block them, and three commands to run on the host after a session.
  • README, allowed-domains.txt section: the "Why the script is in the image" paragraph now says the agent can't edit the allowlist. A new "Shared CDN addresses" note explains that the firewall allows IPs, not names, so a CDN host opens other sites on the same addresses (refs claude-code template: the sandbox firewall allows whole shared CDN IPs, so each allowlisted CDN host likely opens unrelated sites #296).
  • README, Quick Start: the compose file's bullet mentions the mount.

Closes #289
Refs #296

Notes

  • Cost for sandbox users: git in the sandbox can't write .devcontainer/. Probed with the published image:

    • git merge of a branch that changes .devcontainer/ fails cleanly (exit 2).
    • git switch reports success but leaves the file as stale content that shows as modified. A later commit -a would revert it.
    • git merge --ff-only fails and leaves other files half updated.

    The README tells users to switch and pull on the host and not to commit .devcontainer/ changes from the sandbox. The upstream-sync skill has to run on the host or in the default variant.

  • Why not option 2 (read-only .git/config and .git/hooks): it breaks git push -u and gh pr checkout, stops husky setting core.hooksPath, and breaks worktree workspaces, where .git is a file and the mount can't start. Making hooks read-only alone does nothing while core.hooksPath stays writable.

  • No native git mitigation exists:

    • safe.directory checks only ownership, and Docker Desktop's fakeowner shows sandbox-written files as the host user (uid 502 in the probe).
    • Git honors only safe.directory, safe.bareRepository and uploadpack.packObjectsHook from protected config alone. Nothing makes git ignore core.fsmonitor, core.hooksPath, core.sshCommand or aliases from repo-local config.
    • A host-side -c or GIT_CONFIG_* override would mean listing every key that runs a command, and it would turn off legitimate hooks too.

    So the README documents the check instead. Probed on host git 2.50: git status runs core.fsmonitor, and on a tty git config --list runs a repo-set pager.config. So the README says to read .git/config with cat first, including any include.path file.

  • Placement: the mount lives in docker-compose.yml (next to the bind it narrows), as [BUG] sandbox: agent can write .git/ and .devcontainer/, which the host then runs #289 suggests. The upstream-sync skill classes that file as starter-customize, so it surfaces the change to adopting projects without applying it.

  • Validation:

    • docker compose config resolves the mount as read_only: true.
    • docker compose run with the sandbox image showed /workspace rw and /workspace/.devcontainer ro. A write failed with Read-only file system, and reads still worked.
  • Wiki: no page goes stale. Cloudflare CLI tells sandbox users to allowlist api.cloudflare.com and dash.cloudflare.com, which are on Cloudflare's shared CDN (claude-code template: the sandbox firewall allows whole shared CDN IPs, so each allowlisted CDN host likely opens unrelated sites #296).

The sandbox bind-mounts the repo read-write, so the agent could edit
.devcontainer/: the host runs initializeCommand from it at the next start,
and the firewall reads allowed-domains.txt from it. Mount it read-only on
top of /workspace. Branch switches, pulls and merges that touch
.devcontainer/ now fail in the sandbox, which the README documents.

.git/config and .git/hooks stay writable: a read-only mount breaks
`git push -u`, `gh pr checkout` and worktree workspaces, and git has no
setting that ignores repository-local config (protected configuration covers
only safe.* and uploadpack.packObjectsHook). The README lists what to check
on the host after a sandbox session.

Also notes that the firewall allows a CDN host's shared IPs (refs #296).

Closes #289
gatezh added a commit that referenced this pull request Nov 27, 2026
…ntainer

The sandbox now mounts .devcontainer/ read-only (#289, PR #319). The
skill checks test -w .devcontainer first and, when it fails, audits and
reports instead of starting edits it can't finish; run the sync on the
host or in the default variant. Workflow 1 also flags a sandbox
docker-compose.yml without the read-only mount as a security finding,
next to the existing shared-volumes one. The compose file is
starter-customize, so the skill surfaces the line and asks.

Part of the 1.4.0 release; no further bump.
@gatezh
gatezh changed the base branch from master to claude-code/safe-directory-worktrees November 27, 2026 20:22
@gatezh
gatezh added this pull request to stack #321 November 27, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] sandbox: agent can write .git/ and .devcontainer/, which the host then runs

1 participant