Which of the three is safest?
The docs do not rank them. By what each gives up, the narrowest is --no-Sandbox (only the browser's own isolation) and the widest is allowNestedUserNamespaces (the docs use a warning box and say code can end up running outside the sandbox). That ranking is my judgment.
I added playwright to excludedCommands and it has no effect. Why?
Most likely the pattern. The docs say it must end with *, every command in the call must match, and matching is on the call text, so a playwright run inside npm test does not count. Match the command Claude actually runs.
Can I put it in the project settings.json for the whole team?
Not allowNestedUserNamespaces: the docs say to use user settings and that a repository cannot turn it on. For excludedCommands, entries in project files are ignored while the Sandbox is admin-required.
I'm not an engineer. Why does this matter to me?
If someone switches one of these on just to get tests running, that opens a hole in your security. Knowing the three options and their costs lets you ask the right question in review.
Running Chromium, Playwright or rootless Podman inside Claude Code's Sandbox on Linux or WSL2 often ends in No usable sandbox!. The official sandbox page gives three ways out, and each gives up something different. This article puts them side by side. The facts come from the official sandbox page and changelog; I did not test the three approaches on my own machine, so the trade-offs are the docs' statements plus my own tidying.
The docs say that on Linux and WSL2 commands in the sandbox cannot create user namespaces by default, so tools that rely on them fail. Listed symptoms: Chromium exits with No usable sandbox!; unshare -U true prints Operation not permitted; rootless Podman prints cannot clone: Operation not permitted, or stops earlier with read-only file system on one of its own folders.
For Chromium or Electron, pass --no-sandbox. Claude Code's sandbox stays as it is; the cost is that the browser runs web content without its own sandbox. If the tests only open local pages you control, that cost is small; if they open external URLs, the risk sits at the browser layer. That is my judgment; the docs only say it gives up the browser's own isolation.
Put a command pattern in sandbox.excludedCommands and matching commands run outside the sandbox with your full access:
{
"sandbox": {
"enabled": true,
"excludedCommands": ["npx playwright test *"]
}
}
The docs list several rules that catch people:
*; a pattern with no wildcard is an exact match, so docker matches only docker with no arguments.npm ci && docker compose build stays sandboxed unless another entry covers npm ci.make target that calls a tool internally does not match, and neither does /usr/local/bin/docker. For a browser, match the test command, not the browser.cd or $(...) keeps the whole call sandboxed.The docs add a warning: Claude can edit a script in your working directory before running it, and an excluded command has your full access, so excluding a command that runs a script also lets that script's contents out of the sandbox. Excluded commands still go through the normal permission flow; in auto mode the classifier reviews them; in bypassPermissions mode they run without a prompt unless an ask rule matches.
Added in v2.1.305:
{
"sandbox": {
"allowNestedUserNamespaces": true
}
}
The docs say to set it in ~/.claude/settings.json, not the project's .claude/settings.json, and that a repository cannot turn it on. The benefit is that Chromium or Electron keeps its own sandbox and nested bubblewrap or unshare can run. The cost is stated in a warning box: you turn off a security boundary, code from a sandboxed command can end up running outside the sandbox, you should not rely on any sandbox restriction, including protected paths and credentials.files, to stop a malicious command, and in auto-allow mode that command can run without a prompt. The page also says a command beginning with unshare stays sandboxed whatever excludedCommands says, and that this setting alone is not enough for rootless Podman or Buildah, which the sandbox stops in other ways too.
excludedCommands and expect you to accept that those commands have full access.CLAUDE_CODE_SUBPROCESS_ENV_SCRUB=1: the docs say every command then runs sandboxed and none of these settings have an effect; use --no-sandbox for Chromium or Electron and run other tools yourself outside Claude Code.The ordering (smallest scope first, then exclusion, namespaces last) is my recommendation based on how the docs describe each option, not on a comparison test I ran.