File & Network Sandbox
The sandbox limits what the CLI behind a bot can touch on your host: it keeps secrets out of reach and stops the CLI from wrecking your environment. It is configured per bot and works on both Linux and macOS.
Pick a mode
The file sandbox is one switch with three positions:
How to choose:
- Other people will use this bot (group members, Oncall, several authorized users) → choose Allowlist isolation. Private keys, tokens, other repositories and other bots' data are invisible by default.
- Only you use it, but you worry a command will mess up the machine → choose scratch. No allowlist to configure, every tool just works, and anything that breaks is simply thrown away.
- ⚠️ scratch isolates writes, not credentials: the agent can still read the secrets on this machine, including other people's tokens and login state (such as
user-token-*andlark-cli-home/under~/.botmux/data/). Do not use scratch for a bot several people share.
The sandbox governs which files the CLI can access, not who can talk to the bot. Who can talk is decided by On-Call Mode and Permissions.
Turning it on
In the Dashboard (recommended)
- Open the Dashboard → Bot Config → select the bot.
- Under File sandbox, pick Off / Allowlist isolation / scratch (throwaway).
- When switching to Allowlist isolation or scratch, a confirmation dialog explains what the mode does; click Switch. Switching back to Off has no dialog.
- For scratch you can also pick the storage: in-memory or disk.
The Dashboard also checks a few things for you:
- When the bot is used by more than its owner (Oncall, whole-group access, several
allowedUsers, or per-sender auth) but allowlist isolation is off, it suggests turning it on and says whether the current CLI is verified to work. - When you pick scratch, it warns up front if this machine cannot run scratch or can only use disk storage, and lists the missing dependencies and how to install them.
In bots.json
- Leaving out
sandbox, or setting it tofalse, means off;trueis the same as"oncall". - The legacy field
readIsolation: trueis treated as allowlist isolation and migrated automatically at daemon startup.
When changes take effect
New sessions only. A session records its sandbox mode the first time it starts and keeps using that record. Running sessions keep the mode they started with, even across /restart or a daemon restart. To use the new mode right away, start a new topic.
To check whether a session is sandboxed:
- The session card in Lark shows a small line "🛡️ Sandbox: Allowlist isolation" or "🛡️ Sandbox: scratch (throwaway)". No line means no sandbox.
- In the Dashboard session list and kanban, a session whose recorded sandbox mode differs from the bot's current config is tagged "Sandbox ≠ config". Hover to see both values (for example "session uses Off, config is now Allowlist isolation").
"Sandbox ≠ config" is not an error. It means you changed this bot's sandbox mode after the session started, and the session still runs with the old mode.
Sessions that have not started yet (for example, still picking a repo) don't show this tag.
Forcing it on machine-wide
BOTMUX_SANDBOX is handy for testing or blanket hardening and applies to every bot on the machine:
The variable can only force the sandbox on, never off: setting it to 0 does not turn off a sandbox the bot enables itself.
Allowlist isolation (oncall)
The CLI is confined to a per-session file allowlist that governs both reads and writes. However group members try to steer the model, it cannot reach your private keys, other repositories, or Lark app secrets. It is often paired with On-Call Mode.
What the sandbox can see
Things to watch:
- Point the working directory at a specific project (e.g.
~/proj).workingDirdefaults to~, which puts every unhidden file in your home directory on the allowlist, writable. - The working directory cannot be inside the botmux data directory (except the bot's own
bots/<appId>/); such a session refuses to start. - On Linux, the private
/runalso holds a few read-only mounts the session needs: the command relay directory/run/sbxbin, the MCP plugin gateway socket directory (when the gateway is on),/etc/resolv.confwhen it links into/run, and CLI / interpreter directories living under/run(such as fnm or nvm multishell directories).
Adding paths or masks (sandboxPaths)
To let the sandbox see more directories, or hide more sensitive paths:
Rules:
- Use absolute paths (starting with
/or~/). A relative path is resolved against the session working directory, where..may already be your home directory, so none of the three lists accepts one. readWritecannot contain/, your home directory, the botmux data directory, or any parent of them: that would hand the whole disk or every credential to the sandbox. A specific directory such as~/projects/foois fine.- On Linux,
readOnlycannot contain/or/run: the mount points the sandbox needs could not be created and the session would exit at launch. Use specific directories such as/usr,/opt/<tool dir>,/run/lock. - The Dashboard rejects these on save and explains why. Older entries hand-written into
bots.jsonare downgraded at spawn: home / data directory move from read-write to read-only,/and relative paths inreadWriteare dropped, and on Linux/and/runinreadOnlyare dropped too. readWrite/readOnlypaths that do not exist yet are skipped at spawn; to allow a file that has not been created, allow its existing parent directory.- The legacy fields
sandboxHidePathsandsandboxReadonlyPathsare still read and are migrated todeny/readOnlyat daemon startup.
Where each CLI keeps its data
- Claude Code (including Seed, built on it) and Codex: config, transcripts and memory live in the bot's own directory
<BOTMUX_HOME>/bots/<appId>/(.../claude,.../codex) instead of your global~/.claude/~/.codex. The Dashboard shows "Enhanced CLI data isolation". - Other CLIs (Cursor, Antigravity, Grok, Kimi, …): keep using their global data directory on the host, mounted into the sandbox as each adapter declares (some writable as a whole directory, some only their credential files).
- With
wrapperCliconfigured, this redirect is skipped and the CLI uses its usual data directory.
Which CLIs are verified
These CLIs were tested under allowlist isolation on Linux (start, first turn, shell tool, working directory read/write, network, botmux send and credential isolation, on both tmux and pty backends):
Claude Code, Codex, Antigravity, OpenCode, Pi, oh-my-pi, Grok, Kimi.
- Codex App does not support allowlist isolation on Linux and refuses to start; use Codex instead.
- Other CLIs have not been verified one by one; try one in a test session first.
Using it with wrapperCli
A bot with a launch prefix (wrapperCli) can also be sandboxed (pty / tmux backends). The wrapper itself runs inside the sandbox, under the same allowlist:
- botmux only lets in the wrapper's own executable file and the CLI it calls.
- Anything else the wrapper needs (its install tree, interpreter, config) must be added to
sandboxPaths:readOnlyfor reading,readWriteif it writes. - When a path is missing, the session names it before starting; if the wrapper exits right after launch, the topic also suggests adding the paths to
sandboxPaths. Under scratch it suggests checkingscratchDenyPathsinstead.
Multiple accounts & credentials
- Codex isolated login (
codexAuthSync: "isolated"): pointsCODEX_HOMEat<BOTMUX_HOME>/bots/<appId>/codexand never reads or touches the global~/.codex. Works with the sandbox off or in allowlist isolation; it cannot be combined withscratchorwrapperCli(the session refuses to start). When a session is bound to a non-legacy Codex instance, the instance's own auth mode applies. - Codex
config.toml: when Codex uses the bot's own directory (allowlist isolation, orcodexAuthSync: "isolated"; not under scratch or withwrapperCli), theconfig.tomlin it is copied once from the host's~/.codex/config.tomlwhen the first new session starts; later host edits are not synced. The Dashboard (next to "Codex login credentials") shows the path and offers Re-sync from host (the current file is backed up asconfig.toml.bak-<time>first), effective for the next new session. - Claude per-bot accounts (
credentialsSourceDir): aclaude-codebot takes its OAuth credentials from this directory on every cold start, with allowlist isolation (oncall) or the sandbox off. An unsandboxed bot therefore switches to its own CLI data directory, without adding file access restrictions. Cannot be combined withcodexAuthSync: "isolated"orscratch. - lark-cli: the sandbox hides the shared
~/.lark-cli. To use lark-cli inside the sandbox, the machine must first split lark-cli config per bot; see lark-cli per-bot config (Chinese).
Several accounts on one machine: a separate account for a Claude bot
By default every sandboxed bot on a machine takes its credentials from the shared login (~/.claude/.credentials.json or the keychain), so they all run as one Claude account. To give one bot a different account:
-
Prepare an account directory with one sub-directory per CLI, for example:
-
Set
credentialsSourceDirfor the bot:"credentialsSourceDir": "~/accounts/acct-b"inbots.json, or send/botconfig set credentialsSourceDir ~/accounts/acct-bin Lark. -
It takes effect for new sessions (
/restartan existing one). From then on, every cold start copies the credentials from that directory into the bot's own data directory.
Limits:
- Only
claude-codeis supported for now, with allowlist isolation (oncall) or the sandbox off;scratchrefuses to start. With the sandbox off, the CLI data directory moves to<BOTMUX_HOME>/bots/<appId>/claude, without adding file access restrictions. Existing transcripts and memory do not move; globalsettings.jsoncontributes onlyenv, whileCLAUDE.md, skills and plugins are not carried over. If the data directory cannot be redirected (for example withwrapperCli), the session also refuses to start. - If the source directory is missing, unreadable or holds invalid credentials, the session refuses to start instead of quietly falling back to the shared login.
- Cannot be combined with
codexAuthSync: "isolated". For separate Codex accounts usecodexAuthSync: "isolated", see the item above. - botmux only copies on cold start and does not refresh the tokens in the source directory; keeping them valid is up to you (or an external script).
/botconfig unset credentialsSourceDirgoes back to the shared login.
scratch (throwaway sandbox)
A disposable environment for your own use.
How it works
- Reads: zero setup. The bot sees the full real filesystem; compilers, global npm / pip packages,
~/.gitconfigand project configs just work. - Writes: all go to a copy. Editing
/etc, installing global packages, changing your home directory or project files: every write lands in a separate copy-on-write layer that is discarded when the session ends. - Linux: based on overlayfs, with zero writes to the host disk. A root daemon uses kernel overlayfs; a non-root daemon falls back to
fuse-overlayfsautomatically. Separately mounted data disks (such as/data00): under root each gets its own copy layer; under non-root they are read-only inside the sandbox, so keep the working directory on the root filesystem, otherwise the session refuses to start. - macOS: uses APFS clones of your home directory and project (only changed blocks take space), with system paths read-only. But
~/Library/{Caches,Application Support,Logs}and system temp dirs such as/private/tmpand/private/var/foldersstill write to the real disk and are outside the throwaway guarantee.
Storage and options
macOS always uses APFS clones; there is no memory / disk choice.
Network sandbox
The file sandbox does not restrict networking by default: network and proxy access inside the sandbox are the same as on the host. To restrict it, add one of the following.
Block all network (sandboxNetwork: false)
The CLI runs in a network namespace with no outside access. Good for purely local, offline tasks.
Allow by destination IP (sandboxNetworkPolicy)
Use this when the sandbox should reach only certain internal APIs or a proxy. Linux + pty backend + allowlist isolation only.
- Public (
public) and private (private) ranges are set separately; each can beallow(everything),block(nothing),allowlist(only matching rules) ordenylist(everything except matching rules). - Rules use IP / CIDR only and can be limited to TCP / UDP ports; domain names are not supported.
- Filtering happens in the kernel (nftables + slirp4netns) on the real destination IP of each packet.
- In the Dashboard: Bot Config → Destination IP network policy; edit and click Save policy, or Clear network policy to remove it.
- Trusted Proxy Egress (
proxyMode: "trusted-egress"): Ordinary sessions may explicitly delegate proxied business destinations to a trusted exit; the proxy socket itself remains subject to destination IP and port rules.
Check two things first, otherwise sessions either start without network access or do not start at all:
- Set
dnsServersexplicitly. With a policy, the sandbox's/etc/resolv.confcontains only thednsServersaddresses and slirp4netns' built-in DNS forwarder is disabled. Without them there is no DNS and every lookup fails (getaddrinfo EAI_AGAIN) — an allow-all policy included. Use the nameservers from the host's/etc/resolv.conf(with systemd-resolved that file says127.0.0.53, which the sandbox cannot reach; use the upstream servers in/run/systemd/resolve/resolv.conf). Only port 53 is opened to them, even inside a blockedprivatezone. The Dashboard's starting template fills in the host's current nameservers. - Choose a trusted exit explicitly for ordinary proxy sessions. If the daemon or the bot's
envsetsHTTP_PROXY/HTTPS_PROXY/ALL_PROXY(any case), a policy that is not allow-all refuses to start sessions: the proxy resolves and forwards destinations, so the kernel rules only see the proxy. Once the exit is trusted, add"proxyMode": "trusted-egress"and permit the proxy's TCP addresses and ports, or remove the proxy variables. Launch validation resolves every proxy endpoint's complete A/AAAA list and refuses any address rejected by zone rules or ordered drops, any port or protocol mismatch, missing or invalid DNS answers, and invalid URLs. Loopback and network gateway aliases cannot be proxy exits. Validation neither rewrites environment variables nor widens kernel rules; the proxy's ACL remains responsible for destinations behind it.
When a plugin freezes a protected HTTP egress policy into a session, only the codex CLI currently supports the protected model bridge; other CLIs are rejected before launch. This mode cannot be combined with general proxyMode: "trusted-egress" delegation or task proxy variables. Conflicts fail explicitly: remove task proxies, clear general proxy delegation, and use the protected model bridge for model connections. The bridge forwards authorized model service connections only; it is not a general HTTP/CONNECT proxy. Direct connections to protected destinations are denied by their frozen IPs and ports within the existing policy; other destinations continue following their existing rules.
Authentication tokens live in the separate egress-private subtree of the socket directory (0700 directory, 0600 file). The task's file sandbox masks both /run/botmux-mcp/egress-private and its canonical host path. Model and declared local-service bridges read tokens outside the file sandbox; tasks only see the sockets. The runner must install nft rules successfully before readiness, bridges, or task execution. Failure exits instead of using a policy-presence boolean or unused environment flag as proof. Decision logs and unregistered-mutating-candidate warnings omit queries, request headers and bodies.
Shared business reads use BOTMUX_PROTECTED_EGRESS_PROTOCOL=shared-read-v1, injected by the sandbox alongside the socket. A supporting CLI keeps the host's existing business login credentials without reading the guard token. The x-botmux-egress-client: shared-read-v1 marker selects a shared exit, not a user identity or write authorization. The guard must explicitly enable this protocol, still validates the frozen policy and target, and blocks writes registered in denyRoutes. POST queries work without a separate read-operation registry. Internal Botmux headers are stripped from business requests; shared requests carrying an authentication token or any x-botmux-loopback-* header are rejected and cannot reach host identity services through this exit. Existing model and controlled Lark identity bridges retain private token authentication. Protected writes must still go through the plugin's per-call checks of the current human principal and capability, never the shared business identity.
Deploy the protocol to both Botmux and the calling CLI. Persistent older CLIs may retain their original startup environment; start a new topic after installation and restart. Unknown protocols or missing required sockets must fail without falling back to a direct protected-target connection. Non-Botmux use and requests to other targets keep their original behavior.
denyRoutes also denies case-equivalent protected paths. Pathnames reject percent encoding, matrix semicolons, whitespace, duplicate separators and dot paths; no safe encoding allowlist currently exists. Valid pathnames and queries are forwarded unchanged, so legitimate reads need no per-operation registry. Unregistered mutating candidates are still allowed with a warning; the write-route registry must remain complete.
Residual boundary risk: Only the finite frozen IPs/ports are denied directly; other private troubleshooting destinations remain direct, without default-block egress. Other A/AAAA answers, CDN edges and unfrozen alternative addresses can still bypass the guard. This is not complete hostname isolation or proof that every write bypass is eliminated. For absolute bypass prevention, do NOT use default block today (block accepts no exception rules, and the protected model bridge exists only when the model host itself is a protected target, so a separate model gateway would become unreachable). Configure the public zone as an allowlist with a sole exit: list required addresses such as the model host explicitly, or rely on a provably complete service/network authorization boundary. Upstreams currently use only frozenAddresses[0] without multi-address failover; never blindly retry a possibly executed write.
Close cleans its own authentication file and preserves a stable-path token already rotated by a successor. Cross-process rotation between comparison and unlink still has an availability race, without atomic conditional deletion. Serialize overlapping cross-process startup/teardown for the same session; further protocol hardening remains a follow-up.
Other limits:
- The host
PATHneedsslirp4netns(with--disable-host-loopbackand--disable-dns),nft,ipandunshare(with--kill-childand--mount-proc), and bwrap must support--add-seccomp-fdand--disable-userns. Nothing is installed automatically; if any piece is missing, the session refuses to start. - A bot without its own backend setting uses the daemon default (tmux); switch it to pty under "Session backend" in the Dashboard.
- With a policy configured, changing the sandbox mode or backend is rejected until you clear the policy.
- The policy is fixed when a topic is created. After clearing or changing it, existing topics (including ones restored after a daemon restart) keep the old policy; start a new topic.
What works inside the sandbox, and what does not
botmux send still works
On Linux, when the CLI inside the sandbox calls botmux send to post text, cards, images or files, the request is written to a session-private relay directory and the daemon outside the sandbox sends it. On macOS the allowlist sandbox by default calls Lark itself, after the daemon confirms this turn's origin.
Note: by default the allowlist sandbox can read this bot's own Lark App Secret (<BOT_HOME>/send-cred.json); botmux history, botmux quoted and similar commands use it to call Lark directly. Anyone who can steer the agent can therefore have it trade the secret for an app-identity token and skip every daemon-side check. Turn on sandboxWithholdBotSecret below if that is not acceptable.
Sending somewhere other than the current topic (--top-level for the group's top level, --chat-id for another group, --into for another message's thread) also works, but the daemon re-checks the destination:
- The session's own chat is always allowed;
- Any other chat must be a regular group (not a DM, not an external chat) that the bot is in, and the person who sent this turn's message (or the session owner when there is none) must be a member there and allowed to talk to the bot;
- If any of this cannot be confirmed, the send is refused.
Keep the bot secret out of the sandbox (sandboxWithholdBotSecret)
When on:
- The sandbox cannot read
send-cred.json, so the agent never sees this bot's App Secret and cannot mint an app-identity token; botmux send,botmux dispatch,botmux historyandbotmux quotedare written to the session relay directory and executed by the daemon outside the sandbox. This also gives macOS the same relay Linux has;- For
historythe daemon always reads the current session; forquotedthe message must be in this session's chat or it is refused. Images and files from a quoted message are downloaded by the daemon and handed back inside the session relay directory; - Relayed
historysupports only--limit(at most 100),--scopeand--with-card-json;quotedreads one message per call and supports--raw. Other options are refused; - Other host processes' arguments and environment are hidden from the sandbox (on macOS, process-info on other processes and
kern.procargssysctls are denied); - This bot's attachment directory
attachments/<appId>becomes read-only inside the sandbox (incoming attachments stay readable; all writes are done by the daemon); - The session's
lark-clibot identity (the default and--as bot) is unavailable;--as userkeeps working. Other commands that need to call Lark directly from the sandbox (for examplebotmux bots list) fail.
Applies to the allowlist sandbox (oncall) only; scratch is unaffected. Like the other sandbox options it is fixed when a session is created, so a change applies to new sessions.
Fleet commands belong on the host
The sandbox cannot see the supervisor / daemon processes on the host. Running botmux status / logs / start / stop / restart / start-bot / stop-bot inside it prints a notice that you are inside a botmux sandbox and asks you to run the command in a host terminal. The fleet is most likely fine; do not restart it because of this.
Common limits (both sandbox modes)
- No adopt: a sandbox can only wrap a CLI started from scratch, so
/adoptis refused. Start a new session instead. - No Codex RPC input: under a sandbox, Codex uses normal terminal input instead of
codexRpcInput. - No dynamic single card: sandboxed sessions always use the default card mode; see Cards.
- Skills are a snapshot taken at spawn: the enabled managed skills are copied for the session when it starts; after updating a skill, use
/restartor start a new session. Skills installed as links (local-link) or living in a CLI's native skill directory are unavailable under allowlist isolation;botmux skill showsuggests a copy install instead. - Installs inside the sandbox do not reach the host: if the CLI installs a global skill or package or edits global config, under allowlist isolation it either cannot write or writes to the bot's own directory; under scratch it lands in the throwaway copy. Do installs that should apply globally on the host (Dashboard or a host shell).
- Sub-agents are sandboxed too: sub-agents and child processes the CLI spawns inherit the same file and network limits.
- Zero prompt injection (
promptInjection: "none"): fully supported under allowlist isolation; under scratch, Cursor and Antigravity are not supported (their transcript lands in the throwaway copy and cannot be captured); other CLIs work.
Supported session backends
Prerequisites in containers / restricted hosts
The Linux sandbox relies on kernel namespaces, which Docker-style containers and hardened hosts often block by default. Check per mode:
Notes:
- Which bwrap: the distro binary at
/usr/bin/bwrapor/bin/bwrapis preferred; only when neither exists is a bwrap fromPATHused, with a one-time warning in the log. Codex installs its own build at~/.local/bin/bwrap; when that comes first, sandboxed sessions exit right after launch. Install the distrobubblewrappackage to fix it. - A setuid system bwrap (such as Debian 10's
/usr/bin/bwrap0.3.1) creates the sandbox's user namespace as root. When botmux runs as an ordinary user, the kernel then refuses it the sandboxed CLI process's/proc/<pid>/fd, even under the same uid. TRAE (traex) identifies its session from the kernel lock table/proc/locksinstead, so replies are still collected; other CLIs that locate their transcript through the files their process has open may not get their replies collected on such a host — the notice in the thread then says "permission denied", and the worker log names the process and the cause. There is no need to remove the setuid bit or loosen kernel settings for this, and you should not. - Symlinked system directories: when
/opt,/usror/etcis itself a symlink, the sandbox recreates the same symlink inside. If the real path is a directory of the same name (/opt -> /data00/opt), it is mounted read-only as before; if it points anywhere else (such as the root of a data disk,/opt -> /data00), only the link is recreated and the target is not granted — just the working directory, the CLI runtime and whateversandboxPathsgrants explicitly are visible under it, so the baseline/optgrant never exposes a whole disk. Add the toolchain subdirectories a session needs from/opttosandboxPaths.readOnly. - No downgrade by dropping PID isolation: other bots' processes on the same host hold plaintext credentials in their environment, which a sandbox without PID isolation could read through
/proc. So a normal deployment refuses to start when procfs cannot be mounted (only the core-only deploymentBOTMUX_CORE_ONLY=1allows it).
botmux never falls back to running the CLI unsandboxed; it refuses to start the session instead. Common messages:
Troubleshooting
-
Try bwrap directly:
If it fails, namespaces are blocked; fix that first, nothing on the botmux side needs to change.
-
Check whether unprivileged user namespaces are disabled:
cat /proc/sys/user/max_user_namespaces;0means disabled;- some distributions also have
/proc/sys/kernel/unprivileged_userns_clone;0means disabled; - newer Ubuntu releases may restrict them through AppArmor (
kernel.apparmor_restrict_unprivileged_userns).
-
Inside a container: the default seccomp profile may block
clone/unshare, and AppArmor / SELinux may blockmount. Relax this through your container runtime, e.g.--security-opt seccomp=.... -
scratch as non-root: make sure
ls -l /dev/fuseshows the device andfuse-overlayfsis installed; containers need the device passed through (e.g.--device /dev/fuse). scratch as root also needs mount capability in a container (e.g.--cap-add SYS_ADMIN). -
Network policy:
bwrap --helpmust list--add-seccomp-fdand--disable-userns; upgrade bubblewrap if it is too old.
Relaxing container isolation weakens the container's own security boundary, so weigh it for your environment.
Three things that are easy to mix up
- An Oncall directory is not a sandbox:
/oncall bind <dir>anchors the bot to a working directory in this group and lets members talk to it directly; it does not restrict which files the CLI can read or write. Enable allowlist isolation for that. - CLI auto-approval is not "sandbox off": the auto-approval flags botmux adds by default (
--dangerously-*,--yolo, etc.; turn them off withdisableCliBypass) only disable the CLI's own approvals / sandbox. The botmux file sandbox wraps the CLI from outside and still applies. /grantonly grants talk access: it lets members talk to the bot, but gives no operate rights such as/cdor/restart, and does not change the sandbox or credentials. See Permissions.
Several people on one bot: isolation is stacked
No single layer covers everything; combine them as needed:
