Repository navigation
feat(bots): owners can turn a bot's command sandbox and its network on or off; a sandbox that can't start says why and offers a fix - #2507
Merged
Conversation
…ot test fixtures start a sandbox
…o end in the engine; owner-only routes checked
…s switches, Turn off and Install what's missing About → Can use gets Sandbox commands and Allow network for sandboxed commands under Run commands, read from bots.sandbox.get when the section opens and after each detail refresh, greyed with why where this window can't set the bot up. A stale save reads the setting again. Mousse's sandbox card in the chat says why, that the work waits, the details, and offers Turn off sandbox for this bot and Install what's missing (only where a package fixes it); once the sandbox starts or is off it says what holds now. Install opens the owner's terminal on the bot's computer in the side panel, types the command without Enter once the shell shows its prompt, and checks again when that terminal ends or closes.
- botSandbox on the Codex driver: probes the entry's own Codex with codex sandbox under a profile like the bot's; Windows reads every file and blocks the network only with Codex's elevated sandbox; botHold removed - codexTurnPolicy and the thread config follow the policy: held keeps the profile or workspace-write with the owner's network, open runs commands without a sandbox but still asks, unavailable has no command tool - the loaded thread's key carries the policy kind, network and revision - a retry outside the sandbox is declined only while held; a command while unavailable gets the refusal text - a command whose sandbox failed to start is reported to startFailed once per run
…ked user namespaces
…eep the network they had
Claude Code gives the resolver its own sandbox support: Windows has none; Linux and WSL 2 need bubblewrap and socat on the entry's own PATH, user namespaces, and no Windows drive mounted (Claude Code 2.1.291's sandbox fails every command on WSL 2 with C: mounted); macOS starts Seatbelt. With the network open the support also starts Mousse's proxy. A bot turn reads only its sandbox policy. Off: Bash runs with no sandbox, through the grant gate, with Claude Code's subprocess scrub keeping provider credentials out of commands. Held: today's sandbox, with the network blocked by an empty strict host list, or open through Mousse's proxy on network.httpProxyPort (and, on macOS, the certificate service Go tools need). Unavailable: no Bash, and any command is refused with what to tell the owner. A locked entry without sandbox evidence for its version is unavailable when held, never open. A sandbox that fails to start, at Claude Code's start or at a command, is reported to the engine instead of failing as a command; a turn whose Claude Code would not start runs again without commands. The proxy never reaches this computer's loopback, unspecified or link-local addresses. The old per-driver decisions are gone: claudeSandboxFact, botHold, botWithheldTools, the owner entry's sandbox check and botShellWithheld.
… nested writable folders writable, and tells a failed sandbox start from a command's failure
…ts command sandbox says
…as its command sandbox says
…ns there only with the sandbox off
…the claim is not about it)
…wner's card; docs say Pi runs on Mousse's runner
# Conflicts: # src/mms/bots/activation/BotEngine.ts # src/mms/bots/chat/BotChatService.ts # src/renderer/components/bots/BotCards.tsx # tests/renderer/fakeBotsClient.ts
Collaborator
Author
…nner refusal parks the work; subagents probe their own entry; upgrade keeps held paths held and says which are newly held
…lure is read, so the card never shows a secret
…e person mark's limit
…dbox start failures; the WSL drive detail spells C:\Program Files\ClaudeCode
…x rules files would let a command skip its approvals and sandbox Codex 0.162.1 checks every command against the rules files of its active config layers (the Codex home, the system config folder, trusted projects' .codex folders) before any approval. An allow rule skips the approval and, with the sandbox on, the sandbox. Its app-server has no switch that leaves them out of one thread, so a bot thread that would load one starts without command tools and each turn tells the bot why.
…net addresses only, never this computer's own addresses or the owner's private network
…ess scrub, and Mousse's command file keeps the provider's credentials out of each command
… sandbox on or off Codex gives a command every variable of its own process unless the thread's shell_environment_policy says otherwise, and the owner's own set and filters merge under the thread's key by key. A bot thread with commands now inherits only Codex's core variables, sets the bot's command environment (lockedEnv, as Pi's commands get it) over them, keeps only those names in the form the owner's config uses, and turns login shells off. Checked on the real 0.162.1: GH_TOKEN and the owner's own set no longer reach a command; PATH keeps Codex's helper folders.
…dbox-setting # Conflicts: # docs/bots.md
…errides, from the one list its launch passes The probe decided Windows' elevated sandbox from config.toml alone and ran codex sandbox without the entry's -c overrides, so it could pass while commands ran unelevated with the network blocked only by proxy variables. The launch, the sign-in process and the probe now take their arguments from one function; the probe applies its config overrides (and --enable/--disable) over config.toml, runs under them, and probes again when they change.
…icy to claudeLockedTools
…is on, with the card; with it off they apply as in the owner's own threads
… every -c, as Codex does
…he owner's Codex config sets one
…rpose address registries The refused set is now the full IPv4 and IPv6 special-purpose registries (as updated 2025-10-09), kept in code row by row with one CIDR helper, plus multicast and IPv6 outside 2000::/3. Rows the registry marks globally reachable (anycast PCP, TURN and DNS-SD registration, AS112, AMT, ORCHIDv2, DETs) are refused too. IPv4-mapped, NAT64 and 6to4 addresses are still judged by the IPv4 address they carry; the deprecated ::a.b.c.d form is no longer read as IPv4. 3fff::/20 and 5f00::/16, among others, were reachable before.
…writes its notice with the setting; waiting work resumes only when every launcher it met starts; runner failures and cards are keyed by launcher
…ide it The bot profile denies the whole disk below what it grants, so Codex neither retries a failed command outside the sandbox nor widens an approved require_escalated command. With the sandbox on, a command approval with a reason or extra permissions is declined. Windows, whose sandbox can't deny, makes the Codex sandbox unavailable. macOS bots read Homebrew's folders so its programs start.
…h can't run there while the sandbox is on
…s stay per bot; parked work keeps its launchers; cards settle when off; Install reads the card's launcher - Every first write of a bot's sandbox setting (start, About, a turn, the owner's change) writes its upgrade notice in the same transaction; while it fails, the default is read without being kept. - A Codex command_rules failure is never kept launcher-wide: the rules are read per bot folder at each resolve. - The launchers parked work waits for are kept with it, so a restart doesn't wake it while the runner is still down. - With the sandbox off, every card settles, whatever launcher it names. - Install what's missing sends the card's launcher entry and adds that launcher's packages.
… folders, and gh gets its own config folder Codex's Seatbelt profile lets every :minimal command write /private/tmp and /private/var/tmp unless the profile denies them. Under the profile gh stops at an unreadable ~/.config/gh, so held Codex bot commands get GH_CONFIG_DIR in the bot's scratch.
New bots and bots from before the setting start with the sandbox off and the network open for when the owner turns it on. The upgrade writes that default with nothing posted in the chat; the per-runtime upgrade rules, the upgrade notice and the old secret runner's bubblewrap lookup are removed with their tests. Tests about held commands turn the sandbox on first. The device-access test now covers the bots.sandbox methods.
…tall is decided per card; an older bundle arrives off - A launcher not probed since the start or a recheck never counts as started for waiting work, and one that failed is probed again: parked work is looked at again once those probes end. - The card's Install answer is kept per card launcher, so a stale card never hides Install elsewhere. - A bot moved from an older build without a saved setting arrives with the default, off.
# Conflicts: # src/mms/bots/activation/BotEngine.ts
…'s provider and the runner read; a card's nothing-to-install is kept per card - sandboxView looks at waiting work, probing the launchers it waits for, even when the work's entry and Mousse's runner can't start, so work parked for a launcher repaired alone carries on. - Install's 'nothing to install' is remembered by the card (its message and place), so a later card for the same launcher, posted when its package went missing again, offers Install.
This was referenced Dec 1, 2026
Merged
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.




Problem
A bot's command sandbox was decided inside each provider's code from platform checks, and no owner could change it.
socatorbubblewrap, every command of a Claude Code bot failed before it ran. The bot could only tell its owner to install a package and restart Mousse.api.github.comwithghorcurl, because sandboxed commands had no network.Change
Each bot now has two owner settings in About → Can use, under Run commands:
Only the owner can change them, from a Mousse window: locally from the app window, or from another device whose router marks the call as a window's. A bot, the CLI, an agent or MCP can't change them, and Allow everything leaves them alone. They are stored per bot in
bots.db(v19, tablebot_sandbox), with a revision. A change made from an older view is refused.One resolver.
BotSandboxResolverturns the setting, the provider entry (or Mousse's own runner) and the command's environment into exactly one of three results:open: the sandbox is off.held: a sandbox that was tested and starts.unavailable: a reason, and whether installing a package fixes it.It is a required field of a bot's authority, so no launch is built without it. About, the chat card, the bot's system text and every launch read this same result. The old per-driver decisions (
botHoldand its platform checks) are removed.Off removes only the sandbox. Grants, approvals, destructive-command cards, secret masking and the filtered command environment all still apply, on every provider:
CLAUDE_ENV_FILEunsets the provider's sign-in variables before every command.shell_environment_policy, so variables such asGH_TOKENdon't reach them. The bot's ownPATHwins over aPATHin the owner'sset. It keeps its approval gate, so a bot without Run commands still can't run a command.On, per launcher:
mousse-botprofilemousse-botprofile, also reading Homebrew's foldersbashsandbox-execprofileNetwork open on Claude Code goes through a small Mousse proxy on
127.0.0.1, passed asnetwork.httpProxyPort. The pinned CLI refuses a bare*host list, which is why the proxy exists.CONNECTwithout reading the traffic, soghandcurlverify certificates as usual.2000::/3;::ffff:, NAT64, 6to4) are judged by that IPv4 address.Network open on Mousse's runner uses this computer's network as is. It is wider than the Claude Code path: it can reach services on this computer and the local network.
docs/bots.mdsays so.Codex:
touch ~/outside-test || exit 1) is retried outside the sandbox. Underuntrusted, Codex doesn't ask again before that retry once the first attempt was approved. Codex skips the retry only when the profile denies a path.require_escalatedruns, once approved, under the profile widened to write everywhere except what it denies.mousse-botprofile now denies the rest of the disk (":root" = "deny") below everything it grants. Codex then never retries outside the sandbox, and an approved escalation keeps the bot's own profile. The bot's folders, the folders it reads and the system's programs stay as granted, because Codex reads the most specific entry and doesn't mask the denied root in bubblewrap or Seatbelt.require_escalatedjustification) or asks for extra permissions is declined. With the sandbox off, nothing changes.workspace-writesandbox can't deny a path, so the Codex sandbox is unavailable there, with the reason "Codex can't keep a failed command from running again outside the sandbox on Windows." and Turn off sandbox for this bot./private/tmpand/private/var/tmp. Codex's Seatbelt profile otherwise lets every command write there. The bot's ownTMPDIRis in its scratch folder./opt/homebrewand/usr/localwhere they exist, so Homebrew programs such asghstart. With the sandbox on,ghgets its own config folder in the bot's scratch (GH_CONFIG_DIR), because it stops at an unreadable~/.config/gh. It has no sign-in there: the owner's tokens are filtered out.-c, then--enable, then--disable).rules/*.rules, which Codex's "don't ask again" writes) to every thread, and an allow rule skips both the approval and the sandbox. A thread can't switch them off.When the sandbox can't start. Each turn first runs a real probe of the program, using the command's own PATH; so does a subagent's start and turn. A real start failure is mapped to the same state, including Claude Code's start errors (bubblewrap missing, socat missing, and WSL with a Windows drive mounted). Mousse then:
socatorbubblewrap). It opens an owner's terminal with the distribution's command typed (apt-get,dnf,pacmanorzypper) and checks again when the terminal closes. No restart is needed. On a card of another launcher (a subagent's entry), it adds that launcher's packages. When there is nothing to install for a card, only that card stops offering it.What a held command printed is masked before it is read, so the card's Details never show a secret. A secret command's start failure is recorded against Mousse's runner, not the turn's provider.
The bot is told the reason in its system text, and to point the owner to the card rather than to install commands.
Changing it while work runs. A tighter setting stops running commands, background commands and subagents that hold the shell. Any change closes the warm chat process, rechecks the sandbox and resumes waiting work.
Subagents are held by the same setting. A subagent whose runtime reaches further than its work's runs without commands.
Defaults: the sandbox is off for every bot, new and existing. Its commands run as the owner's own threads' do, with grants, approvals, secret masking and the filtered environment still applying. The owner turns it on per bot. Existing bots get that row once, at the first start of this version, with nothing posted in their chats. A bot moved from an older build, whose bundle carries no setting, arrives off too. The network choice stored with it is open, which is what a bot gets when its owner turns the sandbox on.
Moving a bot carries the setting (bundle format 3). An older Mousse refuses that bundle before the source moves.
Design and wording: docs/plans/bot-sandbox-setting.md. Reference: "Command sandbox" in docs/bots.md.
Two choices differ from the first plan:
bashruns on Mousse's runner, so it is held on Linux and macOS rather than unavailable.How to review
src/shared/bots/personal/sandbox.ts: types, the default and all wording.src/mms/bots/sandbox/: the resolver, probes, runner, proxy and install command.BotEngine.ts: searchsandbox. This covers setting changes, cards, parking and resume, the upgrade,sandboxOf,sandboxViewandruntimeHold.harness/claude/locked.ts(tools, the command environment file),ClaudeSubscriptionProviderService.ts(the scrub),drivers/claudeCode/.vendors/codex/botSandbox.ts,childPolicy.ts,userSetup.ts,CodexProviderService.ts.secrets/runWithSecrets.ts,bots/watchers.ts,harness/pi/extension/shell.ts.botApprovals.ts.methodTable.ts,BotRouter.ts,RemoteBots.ts.BotSandboxRows.tsx,BotAboutPanel.tsx,BotCards.tsx.The risk is in the launchers. A wrong policy there either runs a command less held than the owner chose, or blocks every command.
Verification
Tier 5. Run on Windows 11.
e3bbc29, merged with master at29d5a02ea:node scripts/verify.mjs <the 61 test files this PR touches, plus the secret and Pi runner tests and the provider config test> --typecheck allpassed: 1657 tests and both typechecks.tests/known-failures.jsonand fail on master too: 4 inbotProviderEntries(botProviderEntries tests fail on a Windows computer with Claude Code set up #2077) and 1 inpiBotGate(piBotGate bash test fails on Windows: Git Bash prints the files folder as /tmp/... #2405).remote/bots.test.tsentries for Bot file tests fail on Windows without the right to make symbolic links #2251 passed and can be removed fromknown-failures.jsonseparately.326376d:node scripts/verify.mjs <the 18 test files of the Codex sandbox, the sandbox setting, cards, Install, the method tables and the remote bot methods> --typecheck allpassed: 747 tests and both typechecks, with the same knownpiBotGatefailure (piBotGate bash test fails on Windows: Git Bash prints the files folder as /tmp/... #2405).c4727c5:node scripts/verify.mjs <the 8 Codex sandbox, setting, Install and card test files> --typecheck allpassed: 452 tests and both typechecks.cf81f65(sandbox off by default):node scripts/verify.mjs <the 19 test files of the sandbox setting, cards, Install, subagent holds, approvals, watchers, transfer, device access, remote bot methods, the secret runner, the Codex sandbox and the Pi gate> --typecheck allpassed: 728 tests and both typechecks, with the knownpiBotGatefailure (piBotGate bash test fails on Windows: Git Bash prints the files folder as /tmp/... #2405).remoteBotApplets(8 tests) andbotAvailableHistory(2 tests) fail on Windows on master too (7659c2993), so they are not in that run.9c0de54:node scripts/verify.mjs <the 12 test files of the sandbox setting, Install, transfer, subagent holds, approvals, watchers, cards, About, device access, remote bot methods, the secret runner and Mousse's runner> --typecheck all: 279 of 280 tests and both typechecks passed. The one failure was a Windows temp-folder cleanup error (EPERM) inbotWatchers. That file passes on its own, and fails the same way at random on the previous head (1 of 3 runs).39b1cd9, merged with master at2d0b27647:node scripts/verify.mjs <the 22 test files of the sandbox setting, Install, transfer, subagent holds, approvals, the method table, relayed owner answers, cards, About, device access, remote bot methods, the secret runner, Mousse's runner, the Claude Code sandbox and proxy, the Codex sandbox and adapter, the provider policy, Antigravity and the Pi gate> --typecheck allpassed: 810 tests and both typechecks, with the knownpiBotGatefailure (piBotGate bash test fails on Windows: Git Bash prints the files folder as /tmp/... #2405).d82ffc1:node scripts/verify.mjs <the 7 test files of the sandbox setting, Install, cards, About, approvals, subagent holds and secret containment> --typecheck allpassed: 117 tests and both typechecks.cf81f65, nothing under the bot profile could read the owner's Keychain, with the network on or off (com.apple.SecurityServeris reachable when the network is on). Only exit codes and sizes were checked:security find-generic-password -s gh:github.comandsecurity find-internet-password -s github.comfind the item outside the sandbox and return "not found" (44) inside it.gh auth tokenwith a token-freehosts.ymlnaming the account returns the token outside, and "no oauth token found" inside.gh api useris authenticated outside, and gets 401 inside (network on).git-credential-osxkeychain getreturns the credential outside, and nothing inside.c4727c5, with the pinned Codex 0.162.1 and a temporaryCODEX_HOME:npx vitest run tests/harness/codexBotEscalationReal.test.tspassed 6 of 6, with the defaultTMPDIRand withTMPDIRunder/private/tmp: a command in the bot's folder runs; a plain write outside fails; Homebrew'sghstarts;touch <outside> || exit 1, printing the denial, is not retried outside;require_escalatedwith and without a justification stays in the sandbox.require_escalatedtests created the outside file.codex sandbox -P mousse-botwith the bot's profile: a write to a new folder under/private/tmpis denied, a write in the bot's folder works, and/opt/homebrew/bin/gh --versionexits 0 withGH_CONFIG_DIRin the bot's folder. Without the Homebrew folders,ghcan't start (execvp … Operation not permitted).keepPasted(1 test) andsecretFetchFiles(6 tests) fail on Windows on master too (npx vitest run tests/secrets/keepPasted.test.ts tests/secrets/secretFetchFiles.test.tsat29d5a02ea), so they are not in the run above.3fff::1included), and allowing ordinary public addresses;PATHwinning over the owner'sset;--enablecomes before a-cthat disagrees;require_escalatedjustification or extra permissions are declined; with it off, accepted by the grant;codexBotEscalationReal, Linux with bubblewrap or macOS) runstouch <outside> || { echo "…Operation not permitted"; exit 1; }andrequire_escalatedwith and without a justification as a bot with the sandbox on, and checks nothing outside is created.C:mounted. With the old scrub setting, the same three runs failed as reported.curl https://api.github.com/zenandgit ls-remoteworked through the proxy. With the network blocked, the request got 403. A write outside the bot's folders didn't persist.CODEX_HOME:GH_TOKENand an ownersetvalue no longer reach a bot's command, andPATHdoes. The ownerset.PATHrow ran on the installed Codex 0.172.0, as 0.162.1 isn't on this PC. Earlier, with the sandbox on and the network open,gh api /zenandgit ls-remoteworked and a write outside was denied.127.0.0.1only.codexBotTools,codexManagedWire,codexBotMousseData) need Linux or the repo's pinned install and were skipped on Windows.Notes
No issue