Repository navigation
fix(#197): add project root + worktrees to sandbox allowRead/Write - #198
Merged
Merged
Conversation
The harness pre-resolves `sandbox.filesystem.allowRead: ["."]` at
session start and silently drops the literal, so reads under CWD
fall through to denyRead: ["~/"] and fail under the sandbox even
though writes work. Defensive fix: add the project root as an
explicit absolute path to both allowRead and allowWrite in the
adopter's project-local <repo>/.claude/settings.local.json
(gitignored, per-machine). Worktrees inherit access automatically
— each worktree carries its own settings.local.json entry,
populated for pre-existing worktrees at adopt/upgrade time and for
newly-added worktrees via the post-checkout git hook.
Why project-local, and is it safe? User-scope ~/.claude/settings.json
is sandbox-write-protected but pollutes every Claude Code session
on the host with every adopter project's path. Committed
project-scope leaks machine-specific paths into the repo. Project-
local settings.local.json is per-machine, per-project, never
committed, and sandbox-write-protected — verified empirically:
`echo >> .claude/settings.local.json` from a sandboxed Bash returns
"operation not permitted" because Claude Code's runtime adds
.claude/settings.{json,local.json} and .claude/skills/ to the
sandbox's denyWithinAllow set at the bubblewrap/Seatbelt syscall
level (not user-configurable, owned by the harness).
The harness's protection is for Bash subprocesses; the agent's
Edit/Write/MultiEdit tools bypass it. This PR closes that bypass
via per-tool permissions.deny rules in the committed
.claude/settings.json on both settings files.
The same protection blocks the framework's own helper when invoked
from inside a sandboxed agent session. /setup-steward adopt,
upgrade, and worktree-init therefore invoke the helper with
dangerouslyDisableSandbox: true after proposing the bypass to the
operator; sandbox-bypass-warn.sh fires its bold-red banner as a
backstop. The post-checkout hook fired from a user-terminal git
checkout / git worktree add writes without bypass because the user
shell is not sandboxed. All three write paths are auditable.
What landed:
- tools/agent-isolation/sandbox-add-project-root.sh: new helper.
With --all-worktrees, writes each worktree's path into that
worktree's own .claude/settings.local.json. Refuses to write
when the target file is not gitignored (git check-ignore guard).
Creates the file if missing; atomic via jq → tmp → mv;
idempotent.
- setup-isolated-setup-install Step P: installs the script under
~/.claude/scripts/ and runs it once with --all-worktrees.
Documents the sandbox-bypass requirement for agent-session
invocations.
- setup-isolated-setup-verify Check 8: live sandboxed read+write
probe of the project root, plus a static cross-check that the
abs path is in the current worktree's settings.local.json.
- /setup-steward adopt: Step 7 gitignore template gains
/.claude/settings.local.json. Step 10 post-checkout hook
extends to chain into the helper. Step 12 grows pass 3 that
runs the helper with --all-worktrees under sandbox bypass.
- /setup-steward upgrade Step 6c: helper runs with --all-worktrees
under sandbox bypass after the worktree-init loop.
- /setup-steward worktree-init Step 1c: helper runs for the
current worktree under sandbox bypass.
- /setup-steward verify: Check 4 requires
/.claude/settings.local.json in .gitignore. Check 8b: static
cross-check that the current worktree's abs path is in its own
settings.local.json.
- .claude/settings.json permissions.deny: gains
Edit/Write/MultiEdit(.claude/settings.{json,local.json}) to
close the agent-Edit-tool bypass. tools/sandbox-lint/expected.json
baseline updated to match.
- docs/setup/secure-agent-setup.md: new "Project-root coverage in
the sandbox allowlists" section with harness-behaviour
explanation, scope-choice table, empirically-grounded security
rationale, helper surface, four invocation points.
- tools/agent-isolation/README.md: table row for the new helper.
Closes apache#197.
Generated-by: Claude Code (Opus 4.7)
potiuk
force-pushed
the
fix-197-sandbox-project-roots
branch
from
May 17, 2026 17:56
e94bc19 to
c9a3b6e
Compare
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #197 — the harness pre-resolves
sandbox.filesystem.allowRead: ["."]at session start and silently drops the literal, so reads under CWD fall through todenyRead: ["~/"]and fail under the sandbox even though writes work. Defensive fix: add the project root as an explicit absolute path to bothallowReadandallowWritein the adopter's project-local<repo>/.claude/settings.local.json(gitignored, per-machine). Worktrees inherit access automatically — each worktree carries its own settings.local.json entry, populated for pre-existing worktrees at adopt/upgrade time and for newly-added worktrees via thepost-checkoutgit hook.Why project-local, and is it safe?
~/.claude/settings.json<repo>/.claude/settings.json<repo>/.claude/settings.local.jsondenyWithinAllow(verified empirically below).Verified empirically in a sandboxed session:
Claude Code's runtime adds
.claude/settings.{json,local.json}and.claude/skills/to the sandbox'sdenyWithinAllowset at the bubblewrap/Seatbelt syscall level — not user-configurable, owned by the harness. A sandboxed Bash invocation cannot mutate the file the fix writes to.The harness's protection is for Bash subprocesses; the agent's
Edit/Write/MultiEdittools bypass it (they're agent-direct). The PR closes that bypass via per-toolpermissions.denyrules in the committed.claude/settings.json. Symmetric protection on.claude/settings.jsonitself is included — maintainers occasionally edit it, but per-callpermissions.askkeeps every write operator-approved.The same protection blocks the framework's own helper when invoked from inside a sandboxed agent session.
/setup-steward adopt,upgrade, andworktree-inittherefore invoke the helper withdangerouslyDisableSandbox: trueafter proposing the bypass to the operator;sandbox-bypass-warn.shfires its bold-red banner as a backstop. The post-checkout hook fired from a user-terminalgit checkout/git worktree addwrites without bypass because the user shell is not sandboxed. All three write paths are auditable.Full threat-model walk in
docs/setup/secure-agent-setup.md→ Security rationale — why project-local is safe to write to.What landed
New helper
tools/agent-isolation/sandbox-add-project-root.sh(executable, Apache 2.0). With--all-worktrees, enumeratesgit worktree list --porcelainand writes each worktree's path into that worktree's own.claude/settings.local.json. Without the flag (post-checkout hook mode), writes only the current worktree's path. Refuses to write when the target file is not gitignored (git check-ignoreguard — defense in depth against a stale.gitignore). Creates the file if missing; updates atomically (jq→ tmp →mv); idempotent.setup-isolated-setup-install— new Step P installs the script under~/.claude/scripts/and runs it once with--all-worktreesagainst the adopter repo. Documents the sandbox-bypass requirement for agent-session invocations.setup-isolated-setup-verify— new Check 8: live sandboxed read+write probe of the project root, plus a static cross-check that the abs path is in the current worktree's.claude/settings.local.json./setup-steward adopt— Step 7 gitignore template gains/.claude/settings.local.json. Step 10 post-checkout hook content extends to chain into the helper. Step 12 grows pass 3 that runs the helper with--all-worktreesafter the worktree-init propagation, invoked withdangerouslyDisableSandbox: trueand visible bypass proposal./setup-steward upgradeStep 6c — after the per-worktreeworktree-initloop, helper runs with--all-worktreesunder sandbox bypass./setup-steward worktree-initnew Step 1c — invokes the helper for this worktree's root under sandbox bypass./setup-steward verify— Check 4 now requires/.claude/settings.local.jsonin the adopter's.gitignoreas ✗. New Check 8b: static cross-check that the current worktree's abs path is in its own.claude/settings.local.json..claude/settings.json(framework dogfood + adopter template) —permissions.denygainsEdit/Write/MultiEdit(.claude/settings.{json,local.json})to close the agent-Edit-tool bypass.tools/sandbox-lint/expected.jsonbaseline extended to match.docs/setup/secure-agent-setup.md— new section Project-root coverage in the sandbox allowlists with: harness-behaviour explanation, scope-choice table, empirically-grounded security rationale, helper surface, four invocation points.tools/agent-isolation/README.md— table row for the new helper.Test plan
/setup-stewardand confirm the project root lands in<repo>/.claude/settings.local.json'ssandbox.filesystem.allowRead/allowWrite.git worktree add ../foo feature-xfrom a terminal; confirm the post-checkout hook fires in the new worktree and the path lands in<new-worktree>/.claude/settings.local.json(not in the main's)./setup-steward worktree-initand confirm the sandbox-bypass proposal fires thesandbox-bypass-warn.shbanner before the write.setup-isolated-setup-verifyon a stale session whose project root is not in settings.local.json; confirm Check 8's live probe surfaces ✗.echo "x" >> .claude/settings.local.jsonfrom inside a sandboxed Bash returnsoperation not permitted.Edit('.claude/settings.local.json', ...)call hits thepermissions.denyrule.--dry-run --all-worktreesand verify the per-worktree diff matches expectations without writing..claude/yet — confirm it creates.claude/settings.local.jsonfrom scratch with only thesandbox.filesystemblock.🤖 Generated with Claude Code