Repository navigation
fix(bwclaude): turn Claude Code's own sandbox off inside bwrap - #52
Dan Allan (danielballan) merged 5 commits into
Conversation
The managed settings (compliance role) turn on Claude Code's own sandbox with failIfUnavailable. Inside bwclaude it cannot start (socat is masked) and, where it does, it gives skill scripts no direct network route and a read-only uv cache (NSLS2/ansible#5196). Bind a managed-settings.d/99-bwclaude.json drop-in that sets sandbox.enabled and failIfUnavailable to false; Claude Code merges it after the managed file, so every other managed key stays. Added only when the managed file exists, and only inside the sandbox. Add the main guard so tests can source bin/bwclaude, and a test for the drop-in. Refs NSLS2/ansible#5196 Assisted-by: opencode:claude-sonnet-5-5
There was a problem hiding this comment.
🔵 Needs a closer look
Disabling the inner sandbox leaves ~/.azure unblocked, allowing --ro-path or --rw-path to expose Azure credential caches to Bash tools despite the managed policy.
No open issues 🎉
What changed in this PR
This PR makes bwclaude rely on its outer bubblewrap sandbox by disabling Claude Code’s inner sandbox when managed settings exist.
Changes:
- Adds a sandbox-only managed-settings override.
- Adds focused checks and a sourceable launcher guard.
- Documents the security and networking tradeoffs.
| File | Description |
|---|---|
tests/test-bwclaude-managed-settings.sh |
Checks override contents and mount arguments. |
docs/bw-wrappers.md |
Explains sandbox behavior and lost protections. |
bin/bwclaude |
Adds the managed override and sourceable entry point. |
Review effort: Balanced
The managed Claude Code settings deny reading ~/.azure, but with Claude Code's own sandbox off inside bwclaude the launcher's blocked list is the only guard, and it did not name ~/.azure. Add it, with a test for the credential directories in that list. Found by Copilot review of NSLS2#52. Assisted-by: opencode:claude-sonnet-5-5
A directory made with --dir in the sandbox's root tmpfs is writable. With Claude Code's own sandbox off, a command could write a file into managed-settings.d/ (merged after the managed file) and override the managed policy for the session. Make /etc/claude-code a tmpfs of its own and remount it read-only after the managed files, drop-in and skills are bound into it. Found by Copilot review of NSLS2#52. Assisted-by: opencode:claude-sonnet-5-5
There was a problem hiding this comment.
Copilot was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.
SCRIPT_DIR came from $0, so sourcing bin/bwclaude from a script outside tests/ (or with bash -c) failed to find lib/bwrap_sandbox_lib.sh. Use BASH_SOURCE[0], as bwopencode2 does; run directly the two are the same. Test it by sourcing from another directory and checking for a function of the library. Found by Copilot review of NSLS2#52. Assisted-by: opencode:claude-sonnet-5-5
The comment in bin/bwclaude, the launcher header and docs/bw-wrappers.md said socat is masked inside bwclaude. It is not in _MASKED_BINS. Give the actual reasons for turning Claude Code's own sandbox off: its proxy-only network and read-only uv cache break skill scripts (NSLS2/ansible#5196), and failIfUnavailable stops claude on a host without bubblewrap and socat. The message of the first commit repeats the wrong claim. Found by Copilot review of NSLS2#52. Assisted-by: opencode:claude-sonnet-5-5
There was a problem hiding this comment.
🔵 Needs a closer look
Disabling the inner sandbox removes security protections and conflicts with PR #47’s policy, requiring human security-policy review and managed-host validation that remains unperformed.
No open issues 🎉
Review effort: Balanced
Summary
bwclaudebinds a managed-settings drop-in,/etc/claude-code/managed-settings.d/99-bwclaude.json, that turns Claude Code'sown sandbox off inside the
bwclaudesandbox. The outerbwrapsandbox is theboundary, as in
bwopencode2.clauderun outsidebwclaudekeeps the strictmanaged policy.
Why: the managed settings of the
compliancerole setsandbox.enabledandsandbox.failIfUnavailable. Insidebwclaude:proxy that allows no host by default) and a read-only uv cache, so skills that
connect directly fail with a name resolution error (NSLS2/ansible#5196). That
is
pvws.py, and from reading the scripts most of the Loki, Mimir, Tempo,NeDi and archiver readers too. The ldapsearch-based
bnl-ldapcannot use anHTTP proxy at all.
sandbox.failIfUnavailable,claudealso refuses to start on a hostwithout
bubblewrapandsocat. (socatis not masked in the launcher: anearlier revision of this text and of the first commit message said so, and
that was wrong.)
Description
build_managed_claude_pathsbinds a drop-in with{"sandbox":{"enabled":false,"failIfUnavailable":false}}after the managedfile. Claude Code merges
managed-settings.d/*.jsonafter the managed file,so every other managed key (telemetry,
allowUnsandboxedCommands, ...) staysin force. It is added only when the managed file exists.
CLAUDE_MANAGED_DIRis a plain variable so the tests can point it at ascratch directory.
bin/bwclaudegets the samemainguard asbwopencode2, so a test cansource it, and finds its library from
BASH_SOURCE[0]instead of$0(fourthcommit; Copilot's third review), so it can be sourced from any directory. Run
directly the two are the same. feat(bwclaude,bwcodex): sign in to the AI gateway with your own n2c-token #47 makes the same one-line change.
docs/bw-wrappers.mdexplains whatbwclaudenow relies on and what it loses.~/.azureis added to the launcher's blocked-path list (second commit), withtests/test-blocked-paths.sh. Copilot's review pointed out that the manageddenyReadlist names~/.azurebutmain's list did not, so with the innersandbox off
--ro-path ~/.azurewas allowed. feat(bwclaude,bwcodex): sign in to the AI gateway with your own n2c-token #47 has the same two library linesand the same test file.
/etc/claude-codeinside the sandbox is a tmpfs of its own, remountedread-only after the managed files, drop-in and skills are bound into it (third
commit). Copilot's second review pointed out that a plain
--dirin the roottmpfs stays writable, so with the inner sandbox off a command could add its own
managed-settings.d/*.jsonand override the managed policy. The inner sandboxused to prevent that.
What is lost inside
bwclaude, for reviewers to weigh:with DNS logged by the relay (as in
bwopencode2)..claude/settings, hooks and.mcp.jsonin the working directory. A planted hook could run later outside
bwclaude,unsandboxed, if someone runs a plain
claudein that directory. The same holdsfor the other launchers.
denyReadlist is not lost: the home directory is not mounted and--ro-pathand--rw-pathrefuse those paths (~/.azurewith this change).Open questions:
socaton thehost), and changes the same function (and adds the same
mainguard). If feat(bwclaude,bwcodex): sign in to the AI gateway with your own n2c-token #47 mergesfirst, this needs a rebase and replaces its "stays on" paragraph. If this
merges first, feat(bwclaude,bwcodex): sign in to the AI gateway with your own n2c-token #47 needs the opposite. Decide which behaviour is wanted before
merging either.
compliancerole also be changed for plainclaude? Not done here.Testing
tests/test-bwclaude-managed-settings.sh(new, 7 checks, runs on any host,needs no sandbox): no drop-in without managed settings; managed settings bound
read-only; the drop-in bound after them at
99-bwclaude.json; it setsenabledandfailIfUnavailabletofalseand nothing else; valid JSON; thedirectory is a read-only tmpfs; the launcher can be sourced from another
directory (this check fails with the old
$0line).tests/test-blocked-paths.sh(15 checks, from feat(bwclaude,bwcodex): sign in to the AI gateway with your own n2c-token #47):--ro-pathand--rw-pathrefuse
~/.aws,~/.azure(and below),~/.config/gh,~/.sshand~/.docker, and allow~/.azure-opencode-roand an ordinary directory. Withoutthe library change exactly the four
~/.azurechecks fail.build_managed_claude_pathsrun through a nestedbwrap: before, a command could createmanaged-settings.d/evil.json, a filein the managed directory and in
.claude/, and a subdirectory; after, everyone is refused with "Read-only file system", and the drop-in, the managed file
and the skills still read correctly. The nested test bound a scratch directory
over itself, not the real tmpfs root; the mechanism is the same.
prekon the changed files passes (pixi run --frozen -e dev prek run --files ...).40e74c8) andtested then; this change has not been run through a real
bwclaudelaunchyet. Not tested:
claude -prunning a Bash tool andpvws.pyandmimir.pyinside
bwclaudewith the drop-in, on a managed workstation.Checklist
pixi run -e dev lintlocally (or wait for CI) — see.github/workflows/lint.ymlrunansibledeployment)Assisted-by: opencode:claude-sonnet-5-5