Skip to content

fix(provider-claude-code): SDK sandbox option drops the user's sandbox.filesystem.allowWrite #3034

Open

Description

@smsunarto

Summary

Found while chasing mise WARN failed to write cache file ... Operation not permitted on every command inside bb threads. bb starts each Claude Code thread with its own sandbox option through the Agent SDK, and Claude Code then drops the sandbox.filesystem.allowWrite list from ~/.claude/settings.json. Any tool that writes a cache outside the workspace (mise, bun, pnpm, maestro) fails inside a bb thread and works in a plain claude session. I expected bb to add its roots to my sandbox policy, not replace it.

More generally: we think bb should try to incorporate the user's local sandbox and permission settings wherever it can, for every provider. The user's ~/.claude/settings.json and ~/.codex/config.toml already say which paths, commands, and domains they trust. When bb hands a provider a policy of its own, it should start from that and extend it with the environment's roots, rather than start from a fixed policy and lose what the user configured. #2524 asks for the same shape on the Codex side.

Versions and environment

  • bb 0.41.0 (desktop app), macOS 26 (Darwin 25.5.0)
  • claude-code, claude 2.1.259, @anthropic-ai/claude-agent-sdk 0.3.245
  • Local (non-worktree) environment, permission scope workspace, mode auto
  • ~/.claude/settings.json has sandbox.filesystem.allowWrite: ["~/Library/Caches", "~/.bun/install/cache", "~/.cache", ...]

Steps to reproduce

Without bb, using the options bb passes from buildWorkspaceWriteSandbox:

  1. Put "sandbox": {"enabled": true, "filesystem": {"allowWrite": ["~/Library/Caches"]}} in ~/.claude/settings.json.
  2. Save bb's SDK sandbox option as a settings file:
    cat > /tmp/bb-sandbox.json <<'JSON'
    {"sandbox":{"enabled":true,"failIfUnavailable":false,"autoAllowBashIfSandboxed":true,"allowUnsandboxedCommands":false,"network":{"allowLocalBinding":true},"filesystem":{"allowWrite":["/Users/<handle>/.bb/thread-storage"]}}}
    JSON
  3. Run:
    claude -p --model haiku --setting-sources user,project,local --settings /tmp/bb-sandbox.json \
      'Run exactly this one bash command and report its output verbatim: touch ~/Library/Caches/bb-probe && echo WRITE_OK'

In bb: open a Claude Code thread in auto mode and send the same prompt.

Did not reproduce with: the same claude -p command without --settings. The user list is honored and WRITE_OK prints.

Expected vs actual

# actual, step 3 and inside a bb thread
touch: /Users/<handle>/Library/Caches/bb-probe: Operation not permitted

# mise, on every command inside a bb thread
mise WARN  failed to write cache file: /Users/<handle>/Library/Caches/mise/neovim/0.12.4/exec_env_....msgpack.z Operation not permitted (os error 1)

# expected
WRITE_OK

Expected: the effective sandbox is my allowWrite list plus bb's roots. The Claude Code sandboxing docs say filesystem arrays merge across settings scopes, and bb passes settingSources: ["user", "project", "local"], so the user entries should survive.

Evidence

bb builds the option here, and filesystem.allowWrite only ever holds additionalWorkspaceWriteRoots:

// plugins/provider-claude-code/src/bridge/session-options.ts, buildWorkspaceWriteSandbox()
const allowWrite = params.additionalWorkspaceWriteRoots ?? [];
return {
  enabled: true,
  failIfUnavailable: false,
  autoAllowBashIfSandboxed: true,
  allowUnsandboxedCommands: true,
  network: { allowLocalBinding: true },
  ...(allowWrite.length > 0
    ? { filesystem: { allowWrite: [...allowWrite] } }
    : {}),
};

function buildWorkspaceWriteSandbox(
params: BuildSessionOptionsArgs,
): Options["sandbox"] | undefined {
if (!usesWorkspaceSandbox(params)) {
return undefined;
}
const allowWrite = params.additionalWorkspaceWriteRoots ?? [];
return {
enabled: true,
failIfUnavailable: false,
autoAllowBashIfSandboxed: true,
allowUnsandboxedCommands: true,
network: { allowLocalBinding: true },
...(allowWrite.length > 0
? { filesystem: { allowWrite: [...allowWrite] } }
: {}),
};
}

Those roots are the worktree's git roots plus thread storage. Nothing there reads user settings:

private runtimeWorkspaceWriteRoots(
args: RuntimeWorkspaceWriteRootsArgs,
): string[] {
const roots = [...args.workspaceRoots];
if (args.threadStorageRootPath) {
roots.push(args.threadStorageRootPath);
}
return [...new Set(roots)];
}

settingSources includes user, so this is not the "excluded source" case the docs describe:

settingSources: ["user", "project", "local"],

The effective sandbox config Claude Code reports inside a bb thread lists ., $TMPDIR, /tmp/claude, and ~/.bb/thread-storage as writable and none of the user entries.

Over 7 days of my local Claude Code transcripts I counted 1,252 dangerouslyDisableSandbox retries. The largest groups were bun cache writes, ~/.bb-dev, ~/.local/state, and /var/folders (maestro flows). Every one of those paths is in my allowWrite list.

Thread: thr_6hxm52ewwi, project proj_dhxdkz286e.

What you ruled out

  • Not a stale settings file: the live ~/.claude/settings.json has the list and a plain claude session honors it.
  • Not feat(codex): select named permission profiles in execution controls #2524: that one is the Codex provider, where sandbox_workspace_write.writable_roots replaces the user's default_permissions profile. Same shape, different provider.
  • Workaround: Edit(~/Library/Caches/**) in permissions.allow survives, because Claude Code merges Edit allow rules from every loaded source into the sandbox write set. Step 3 prints WRITE_OK after adding it. That means mirroring every allowWrite entry as an Edit rule, which also widens what the Edit tool may write without a prompt.

Proposal

We should read sandbox.filesystem.allowWrite from the user's settings and append it in buildWorkspaceWriteSandbox, or omit filesystem when the runtime has no extra roots so Claude Code falls back to the user policy. The same principle applies to excludedCommands, network.allowedDomains, and the Codex profile in #2524: bb's policy should be the user's policy plus the environment's roots.

Suggested priority and effort

Medium. Hits every Claude Code user who relies on allowWrite for mise, bun, or pnpm caches. Workaround exists but is non-obvious. Effort probably Low.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report.

AGENT GENERATED — bb thread thr_6hxm52ewwi

Activity

  1. added theissue type on Sep 4, 2026
  2. added
    providers
    provider-claude-code
    confirmed-repro
    on Sep 4, 2026
  3. bb-slop-cop commented on Sep 4, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Low
    • Labels: providers, provider-claude-code, confirmed-repro
    • Report: direct reproduction and root-cause report
    • Verdict: REPRODUCED · confidence high
    • Root cause: the Claude provider builds the SDK sandbox writable-path array solely from bb's additional roots, so user settings are absent from the explicit sandbox configuration.
    • Reproduction: confirmed-repro; the focused regression test failed identically on trusted main in two clean checkouts.
    • Pull request: none — merging user grants into the provider sandbox changes a permission boundary and is not eligible for an unattended simple fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproprovider-claude-codeproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions