With OpenClaw's agents.defaults.sandbox.mode set to non-main, which sessions still run tools on the host, and why can that surprise an operator?
answer
- one session is exempt
- the main session key
- groups get their own keys
- where DMs land by default
- sandbox explain per session
basics
~20 sOnly the agent's main session (agent:<agentId>:main) stays on the host; group and channel sessions have their own keys and are sandboxed. Under the default session.dmScope of main, direct messages share that main session, so they run on the host too.
solid answer
~40 s`non-main` sandboxes **every session except the agent's main session**, whose key is always `agent:<agentId>:main` (or `global` when `session.scope` is `"global"`) and is not configurable. Group and channel sessions get keys of their own, so they always count as non-main and run in the sandbox; the docs call this the common surprise for groups. The opposite surprise matters more for security: with the default `session.dmScope` of `main`, direct messages typically land in that main session, so a DM conversation runs its tools **on the host**, unsandboxed. Giving DMs their own keys with a DM-isolation scope makes them non-main, or you switch to `all`. Check rather than guess: `openclaw sandbox explain --session <key>` says whether that session is sandboxed and which keys change it.
go deeper
Recall that non-main sandboxes every session except the agent's main session, and that group chats are never the main session.
Explain that the test is on the session key, and that the main key is fixed as agent:<agentId>:main or global.
Trace where DMs land under the default dmScope of main and show that they run on the host; prove it with openclaw sandbox explain --session.
Decide when non-main is enough and when an agent must run with all, weighing your own convenience against untrusted DMs and content.
## What `non-main` actually tests OpenClaw's sandbox has three modes under `agents.defaults.sandbox.mode` (overridable per agent in `agents.entries.<id>.sandbox.mode`): | Mode | Which sessions run tools in the sandbox | | --- | --- | | `off` (default) | None, unless an operator role requires a sandbox | | `non-main` | Every session whose key is not the agent's main session key | | `all` | Every session | `non-main` is a test on a **session key**, not on who is talking. The main session key is always `agent:<agentId>:main`, or `global` when `session.scope` is `"global"`. The docs say plainly that it is not configurable: you cannot mark a group as main or the main session as non-main. ## Groups: sandboxed, sometimes unexpectedly Group and channel conversations are keyed separately, for example `agent:main:<channel>:group:<id>` under the default per-group grouping. They never match the main key, so under `non-main` they **always** run sandboxed. That is the configuration's purpose: a group anyone can post into gets a container with no network and no view of the agent workspace by default. It is also why the sandbox troubleshooting page lists "I thought this was main, why is it sandboxed?" as a stock question. A group session hits the sandbox's own tool gate (`tools.sandbox.tools`), whose default deny list includes tools such as `browser`, `nodes` and `gateway`, so a tool that works in your DM can be "blocked by sandbox tool policy" in a group. ## DMs: on the host, often unnoticed The more dangerous surprise runs the other way. Session routing has its own setting, `session.dmScope`, and its default is `main`: **direct messages share the agent's main session** for continuity. Under `non-main`, that means: - your own DM conversation runs its tools on the host, as intended; - so does any other direct message that your channel access rules let in, because it lands in the same main session. The sandbox decision follows the key, so the sender's identity never enters into it. If more than one person can DM the agent, giving DMs their own keys (a per-sender `session.dmScope` such as `per-channel-peer`) makes those sessions non-main and therefore sandboxed. The cleaner alternative is mode `all` with a separate, trusted agent for yourself. ## How to see which side a session falls on 1. Run `openclaw sandbox explain --session <key>`; it accepts short names such as `main`. It reports the effective mode, scope and workspace access, **whether this session is currently sandboxed (main versus non-main)**, the sandbox tool allow/deny and where each came from, the elevated gates, and fix-it config keys. 2. Run `openclaw sandbox list` to see which containers exist and which session or agent each belongs to. 3. Read `openclaw logs` for `agents/tool-policy` entries when a tool vanished; they record the sandbox mode and the rule that removed it. ## Overrides that change the answer - **Per-chat opt-out**: an administrator can exempt one idle chat with `sessions.patch` and `sandboxMode: "off"`. It needs `operator.admin`, persists with that chat, and is not inherited by forks. - **Role-required sandboxing**: a named operator role with `sandbox: "required"` sandboxes that role's new sessions whatever the mode says, cannot be opted out, and fails closed if the backend is unavailable. - **Elevated mode**: an allowed sender can still run `exec` outside a non-main sandbox; it is gated by `tools.elevated.allowFrom`. ## Choosing between `non-main` and `all` - `non-main` fits a personal assistant where **you** are the only DM and groups are the untrusted traffic. Your own session keeps host access. - `all` fits any agent where DMs may come from people you do not fully trust, or where the main session itself reads untrusted content (fetched pages, mail, attachments). - Neither turns one Gateway into a multi-tenant service; OpenClaw's trust model is one operator or one mutually trusting team per Gateway. ## Mistakes that show up in reviews - **Assuming `non-main` means "strangers are sandboxed".** It means "every key except one is sandboxed"; who the sender is never enters the decision. - **Forgetting that DMs follow `session.dmScope`.** A config that opens DMs to more people while keeping the default `main` scope gives all of them the operator's unsandboxed session. - **Debugging by editing config only.** Existing containers keep their old settings until `openclaw sandbox recreate` or pruning removes them, so a fix can look like it did nothing. - **Reading a group's "blocked" error as a bug.** It is usually the sandbox tool gate doing its job; widen `tools.sandbox.tools` for that tool deliberately, not by switching the mode off.
- A tool works in my OpenClaw DM but a group session reports it blocked by sandbox tool policy. Why?The group session is non-main, so it is sandboxed and must also pass the sandbox tool gate `tools.sandbox.tools`, whose defaults deny tools such as `browser`, `nodes` and `gateway`. Allow the tool there (or per agent), or check `openclaw logs` for the `agents/tool-policy` entry that names the blocking rule.
- Can an OpenClaw administrator exempt one chat from the sandbox without changing the agent's mode?Yes. `sessions.patch` with `sandboxMode: "off"` opts one idle chat out and `null` restores the configured policy; both need `operator.admin`. A session whose creator role requires a sandbox cannot be opted out, even by an administrator.
- Under non-main, only the owner's DMs are sandboxed and groups run on the host.
- You can configure which session key counts as main, for example a trusted group.
- Under non-main, every direct message is sandboxed whatever the session settings.
- non-main decides by sender identity, so strangers are always sandboxed.
- non-main moves the Gateway into a container for non-owner traffic.