claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Linux sandbox: duplicate --ro-bind /dev/null for one credential file (built-in denylist + user settings) kills every Bash call on bubblewrap 0.4.0

Open ar4hc opened this issue 1 month ago • 1 comments

Summary

On RHEL 8 (bubblewrap 0.4.0) every sandboxed Bash command fails before anything executes:

bwrap: Can't create file at /home/<user>/.npmrc: Permission denied

The same regular-file credential path is handed to bwrap twice as --ro-bind /dev/null <path>: once from Claude Code's built-in credential denylist (tilde form ~/.npmrc) and once from the user's ~/.claude/settings.json → sandbox.credentials.files (expanded at merge time to /home/<user>/.npmrc). Dedup compares exact strings, so the two spellings of one path both survive.

bubblewrap >= 0.5 tolerates the redundant second bind. 0.4.0 does not, and aborts the entire sandbox, so no Bash command runs at all.

Why the second bind is fatal on bwrap 0.4.0

After the first --ro-bind /dev/null <path>, the destination is a character special file. bubblewrap 0.4.0's ensure_file() early-returns only when the existing node is a regular file; for a chardev it falls through to creating the path, open(O_CREAT|O_EXCL) on the read-only mount returns EACCES, and bwrap exits, tearing down the namespace.

Standalone repro (no Claude Code required)

f=$(mktemp)
bwrap --ro-bind / / --ro-bind /dev/null "$f" --ro-bind /dev/null "$f" true
# bubblewrap 0.4.0 -> bwrap: Can't create file at /tmp/tmp.XXXXXX: Permission denied
# bubblewrap >=0.5 -> exits 0

Contrast cases on 0.4.0:

args result
--ro-bind /dev/null <file> twice fails
--ro-bind /etc/hostname <file> twice (regular-file source) ok
--tmpfs <dir> twice ok

Only duplicated regular-file deny entries are fatal — after the first bind the destination is still a regular file in the /etc/hostname case, so ensure_file() early-returns. Duplicated directory denies use --tmpfs and are harmless.

Repro in Claude Code

  1. A host with bubblewrap 0.4.0 (RHEL 8 ships no newer version).
  2. ~/.npmrc exists.
  3. Add to ~/.claude/settings.json a sandbox.credentials.files entry for a regular-file path that is already in the built-in credential defaults:
    { "path": "~/.npmrc", "mode": "deny" }
    
  4. Start a new session and run any Bash command. Every call fails with the error above; the sandbox never reaches command execution.

Observed argv

Captured by tracing execve on the session's node process. Duplicates marked:

--ro-bind /dev/null /home/<user>/.netrc
--ro-bind /dev/null /home/<user>/.npmrc            <-- 1st
--tmpfs /home/<user>/.ssh
--tmpfs /home/<user>/.ssh
--tmpfs /home/<user>/.azure
--tmpfs /home/<user>/.gnupg
--ro-bind /dev/null /home/<user>/.npmrc            <-- 2nd, aborts bwrap
--ro-bind /dev/null /home/<user>/.netrc
...
--ro-bind /dev/null /home/<user>/.docker/config.json
--ro-bind /dev/null /home/<user>/.docker/config.json

Removing the duplicates from the captured argv and replaying it by hand starts the sandbox fine.

Expected behaviour

Deny binds should be deduplicated by resolved destination before being passed to bwrap, and tilde/expanded spellings of the same path should collapse when built-in defaults are merged with user settings. The deny-write path already dedups; the read-deny / file-mask path appears not to.

A related hazard from the same area: the strings [Sandbox Linux] Re-applying file mask re-exposed by denyWrite bind and [Sandbox Linux] Re-applying denyRead tmpfs re-exposed by denyWrite bind suggest a re-apply pass that can push an additional --ro-bind for a path that was already masked. On bwrap 0.4.0 that would produce the identical crash.

Workaround

Remove from sandbox.credentials.files every regular-file path already covered by the built-in credential defaults — in our case ~/.npmrc, ~/.netrc, ~/.git-credentials and ~/.docker/config.json. Those files stay protected, because the built-in denylist still binds /dev/null over each; only the redundant second bind goes away. Directory entries can stay as they are.

Worth noting for anyone debugging this: a deny path that does not exist is silently skipped ([Sandbox Linux] Skipping non-existent read deny path), so a duplicate entry for, e.g., ~/.git-credentials looks harmless right up until that file is created — then every Bash call starts failing with no config change to point at.

Related issues

Same error string, different root cause: #93129 (deny destinations spelled through symlinks), #85745, #77271.

Environment

  • Claude Code 2.1.273
  • bubblewrap 0.4.0 (bubblewrap-0.4.0-2.el8_10.x86_64) — the newest RHEL 8 provides; upgrading needs root, and sandbox.bwrapPath is honored only from managed settings, not ~/.claude/settings.json
  • RHEL 8.10 (Ootpa), kernel 4.18.0-553.40.1.el8_10.x86_64

Made with AI

ar4hc avatar Oct 27 '26 14:10 ar4hc

Hello from the Claude Code team. The duplicate sandbox bind that broke Bash on older bubblewrap versions should be gone as of 2.1.299. Does Bash work for you there? If not, your bubblewrap version would help.

franklee-ant avatar Nov 23 '26 23:11 franklee-ant