#1238

sandbox: user-level carveouts for credential stores and a per-run or per-MCP-server network option

OpenFabioLeitaoopened 15d ago

Summary

There is no supported way for a user to let selected tools through the sandbox, which makes some everyday tools unusable inside it, while the direction of #815 (approved) is to deny more credential stores. This asks for an explicit, user-level escape hatch that keeps the current security posture.

What happens today (Linux, linux-bwrap, v0.14.0 and main at 8288ae81)

  1. gh cannot see its login. internal/sandbox/profile.go puts the gh config directory (ghConfigDirs, from GH_CONFIG_DIR or ~/.config/gh) on the credential read-deny list. Inside the sandbox a shell command gh auth status prints You are not logged into any GitHub hosts. To log in, run: gh auth login (exit 1), while the same command outside the sandbox is logged in. On this machine the token lives in the OS keyring (hosts.yml has no token), so I have not isolated whether the denied path or the keyring access is what fails.
  2. Stdio MCP servers get a private network namespace when sandbox.network is deny. A local MCP server that needs a loopback relay on the host (the OpenCode browse MCP server, relay on 127.0.0.1:19988) reports browse relay did not start. The process runs in a different network namespace from the host (checked with /proc/<pid>/ns/net). With sandbox.network: allow it runs in the host namespace and works, but that setting is global and also loosens every shell command.
  3. sandbox.network is binary and global. There is no CLI flag, no slash command and no per-server option, so the only choices are deny everywhere or allow everywhere.

Proposal

Keep the defaults and the project-config restrictions exactly as they are, and add, honored only from the global user config and CLI (the same rule already used for sandbox.enabled, network and additionalWriteRoots):

  • sandbox.credentialCarveouts: a list of credential paths the user explicitly lets commands read (for example ~/.config/gh), shown in zero sandbox policy.
  • A per-run network override (for example --network allow|deny) and/or a per-MCP-server network setting for stdio servers.

This pairs with #815: if more stores are denied by default, users need a visible way to allow the few they actually trust.

Notes

  • The reproduction was done on a build of v0.14.0 carrying fork patches that do not touch internal/sandbox/analyzer.go or profile.go.
  • Happy to send a PR once this has the issue-approved label, per CONTRIBUTING.

Activity

1
Vasanthdev200415d ago

Thanks. The three observations hold on main at 8288ae81: the gh config directory is on the credential read-deny list, sandbox.network is allow or deny for the whole run, and neither can be loosened from project config.

Labelled enhancement. I am not marking it approved, because both halves change what the sandbox promises, and that is an owner decision and not a triage one:

  • Credential carveouts let a command read a store the profile denies on purpose, and #815 is about to deny more of them. The questions to settle first are whether a carveout is per path or per program, and how a run shows that one is active.
  • Network scope per run or per MCP server is the smaller ask and stands on its own. A stdio server that needs loopback is a different case from letting every shell command out.

@kevincodex1 this needs your call on direction before anyone writes it. It would also help to split it into two issues, since the second could land without the first.

For the gh case specifically, #1237 is approved and will make gh commands reach the network prompt. Whether gh can then read its login is the carveout question here.