You put your agent in a Docker or Podman container, drop Linux capabilities, mount a read-only root, and cut outbound network access.
Then an MCP tool call still reads local environment variables or touches files outside the workspace.
Nothing "broke out" of the container. The container simply never wrapped the MCP server in the first place. Across four primary sources—the Model Context Protocol Local Server Security guide, OpenClaw's Trust Boundary and Sandboxing docs, Anthropic's Claude Code v2.1.332 release, and ShellBench (arXiv:2611.32946)—here is where the boundary actually sits.
1. "The stdio transport is not a sandbox"
The official MCP Local Server Security specification makes the baseline threat model explicit:
"Your real security decisions happen before launch: what you install (provenance) and how you run it (isolation). The stdio transport is not a sandbox."
A local stdio MCP server is an ordinary operating-system process spawned directly by the host client. Unless you explicitly wrap that child process inside a container (Docker / Podman), a lightweight VM, or an OS sandbox:
- It can read files under your user account (
~/.ssh,~/.aws, plain-text client configs). - It sees any global tokens exported in your shell environment.
- Even if you pin a package version with
npxoruvx, transitive dependencies still resolve at install time—whereas pinning a container image by immutable digest (image@sha256:...) freezes the entire dependency tree.
Where a local server is unavoidable, MCP's guidance is straightforward: run the server binary inside a container with zero extra mounts and speak stdio across the container boundary.
2. Inside OpenClaw: what moves into the sandbox vs what stays on the host
OpenClaw documents two boundaries operators routinely confuse in The trust boundary and What gets sandboxed:
-
Sandboxing is off by default. Out of the box, OpenClaw assumes one trusted operator, so
execruns on the gateway host without prompts. Even OpenClaw's local Codex stdio harness defaults toapprovalPolicy: "never"andsandbox: "danger-full-access"unless explicitly hardened viatools.exec.mode: "auto"(workspace-write+ Guardian review) or an active OpenClaw sandbox. -
Only selected workspace tools enter the container. When Docker, Podman, SSH, or OpenShell sandboxing is active,
exec,ls,read,write,edit,apply_patch,process, and the optional sandboxed browser run inside the sandbox. -
The Gateway process stays on the host control plane. Under Connect MCP servers, the running Gateway owns
mcp.serversdefinitions, shared OAuth flows,SecretRefs, andstdiochild processes. Connecting an MCP server routes tool calls through tool policy (allow/deny), not magically inside your agent's workspace container.
// Hardened OpenClaw + containerized stdio MCP posture (illustrative combined snippet)
{
agents: {
defaults: {
sandbox: {
mode: "non-main", // isolate non-main/group sessions in Docker or Podman
},
},
},
mcp: {
servers: {
"repo-tools": {
// Containerize local stdio servers instead of running bare npx/python on host
command: "docker",
args: [
"run", "--rm", "-i",
"--network=none",
"--read-only",
"-v", "/srv/project-ro:/workspace:ro",
"ghcr.io/example/mcp-repo@sha256:00000000000000000000000000000000"
],
enabled: true,
toolFilter: { include: ["search_*", "read_*"] }
}
}
}
}
Then verify the live effective posture instead of assuming config matches runtime:
openclaw sandbox explain
openclaw security audit
openclaw sandbox explain prints effective sandbox mode, active mounts, tool allow/deny rules, and host vs sandbox resolution; openclaw security audit flags boundary drift with stable check IDs.
3. Claude Code v2.1.332: when skills served over MCP bypass PreToolUse
Even if every runtime tool call runs cleanly inside PreToolUse, agent extensions created a second execution path before the turn even begins.
In Claude Code v2.1.332, Anthropic shipped two paired changes:
-
Skills from MCP servers (beta) (
server:skillin the/menu). -
PreSkillShellCommand— a dedicated hook event triggered on dynamic inline shell commands inside a loading skill.
Why did PreSkillShellCommand have to exist separately from PreToolUse? Because Claude Code skills can embed dynamic shell command blocks that evaluate as the skill renders at load time—before the model invokes Bash or triggers PreToolUse. Pair remote MCP-delivered skills with an unguarded onFailure hook or bypassPermissions, and skill load becomes silent host shell execution.
Blocking load-time skill shell injection in .claude/settings.json:
{
"hooks": {
"PreSkillShellCommand": [
{
"matcher": "Bash|PowerShell",
"hooks": [
{
"type": "command",
"command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-skill-shell.sh",
"args": [],
"onFailure": "block"
}
]
}
]
}
}
Exiting with code 2 or returning JSON permissionDecision: "deny" / decision: "block" stops execution immediately with [not run: blocked by hook: <reason>]. Setting "onFailure": "block" ensures a crashed hook fails closed instead of letting the inline command slip through.
4. What ShellBench shows across 53,100 rollouts
Finally, do not expect switching agent harnesses alone to guarantee safety compliance.
In ShellBench (arXiv:2611.32946), researchers across OpenClaw, UC Berkeley, Red Hat, Hugging Face, and NVIDIA evaluated 12 models across 5 harnesses (OpenClaw, Claude Code, Codex CLI, Hermes, and Pi) over 100 everyday workspace tasks (median 188 files per workspace, 381 safety rubric criteria) totaling 53,100 rollouts:
-
Pass@1 barely differed by harness: all five harnesses scored between 42.9% (Claude Code) and 45.2% (OpenClaw), while top models led at 62.5% (
GPT-6 Astra) and 61.4% (GPT-6.1 Solat ~1/6 token cost). - 15.7% of all rollouts failed a safety criterion. Harness choice explained only 4.7% of the variation in safety failures across the 55 shared configurations, compared to 75.5% from model choice.
- Even on realistic everyday workspaces without adversarial exploits—like a freight reconciliation task—40.3% of submissions (
214 / 531) recommended a duplicate or incorrect payment.
Models still leak secrets or trigger bad actions inside "normal" tasks. Hard runtime isolation—of both the agent workspace and each external MCP server or skill loader—is what stops a bad judgment call from touching real host state.
Practical checklist before your next deploy
- Eliminate unnecessary local stdio servers: Prefer Streamable HTTP MCP with OAuth authorization flows over piping unknown npm/Python packages straight onto your dev host.
-
Isolate unavoidable stdio processes: Run third-party local servers inside Docker/Podman with
--network=none, minimal read-only mounts, digest pinning (@sha256:...), and per-server scoped tokens—never plaintext config literals. -
Gate load-time execution: Configure
PreSkillShellCommandwithonFailure: "block"if you enable skills from remote plugins or MCP servers. -
Verify live posture: Run
openclaw sandbox explainandopenclaw security auditafter any config or harness update.
Honest limitation
This analysis synthesizes primary specifications, documentation, release notes, and published benchmark methodology (Model Context Protocol Docs, OpenClaw Docs, Anthropic Claude Code v2.1.332, and ShellBench arXiv:2611.32946). We did not execute an independent container-escape penetration suite or rerun the 53,100 ShellBench rollouts locally.
Primary References
-
Model Context Protocol — Local Server Security:
https://modelcontextprotocol.io/docs/tutorials/security/local-server-security -
OpenClaw Docs — The Trust Boundary, What Gets Sandboxed, Connect MCP Servers, Codex App-Server Policy:
https://docs.openclaw.ai/start/why-openclaw/the-trust-boundary,https://docs.openclaw.ai/gateway/sandboxing/what-gets-sandboxed,https://docs.openclaw.ai/tools/mcp,https://docs.openclaw.ai/plugins/codex-harness/app-server -
Anthropic Claude Code
v2.1.332Changelog & Hooks Reference (PreSkillShellCommand):https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md,https://code.claude.com/docs/en/hooks#preskillshellcommand -
ShellBench: What Matters More for AI Agents, Models, or Harness for Everyday Tasks (
arXiv:2611.32946):https://arxiv.org/abs/2611.32946
Top comments (7)
One boundary the checklist leaves open: the sandbox protects the host, not the outside world. Your ShellBench example makes the point - 40.3% of submissions recommended a duplicate or incorrect payment. That payment is not host state; it is an outbound tool call, and a contained agent with a networked MCP server can still make it from inside the container. The moment a tool genuinely needs network (payments, email, prod APIs), --network=none is off the table, and the container no longer bounds what the tool does.
Same shape on the Gateway side: SecretRefs stay on the host, so the agent never holds the token - but it can still spend it through any tool call the policy allows. The credential is out of reach but not out of influence.
Do you treat that as a second allowlist problem - per-tool confirmation for anything with an external effect - or is there a layer in OpenClaw that scopes what a sandboxed session may ask the Gateway to do on its behalf?
Sharp distinction—container isolation only bounds host filesystem and OS state, not valid outbound tool calls once network access is open. From OpenClaw's docs (rather than our own penetration test), it splits those controls across tool allow/deny policy per session,
tools.execapproval gates, and host-heldSecretRefsso raw tokens stay off the container. Even then, preventing a duplicate payment or unwanted email still requires a second enforcement layer at the tool/Gateway edge: explicit human confirmation or scoped limits per external side effect, because--network=noneisn't viable there.'The stdio transport is not a sandbox' is the sentence most local MCP setups are quietly built on forgetting. Your Gateway point is the version that bites: the definitions and the stdio children live on the host control plane, so the container wraps the agent's workspace tools while the server process keeps the operator's full environment — ~/.ssh, exported tokens, all of it. Our own MCP server runs as a local stdio process, and the discipline we've applied so far is all at the tool surface — trimming what each tool returns, measuring the context cost — which your piece points out is a different boundary from the process itself. The digest-pinned image versus npx resolving transitive dependencies at install time is the same gap on the supply side. For a single-operator local setup, where do you land: containerize even the read-only servers, or is a tight tool filter plus no network enough for that threat model?
When an agent needs a browser or web session over MCP, do you isolate that browser inside its own disposable remote container rather than letting an MCP bridge launch a browser on the host?
Agreed on the principle—isolating browser automation in its own disposable container or remote browser session (the posture behind OpenClaw's optional sandboxed browser) is much cleaner than letting an MCP bridge touch your daily browser profile, saved cookies, or local network. Speaking from architecture docs rather than running a multi-tenant browser grid ourselves, keeping browser state ephemeral per session avoids turning web access into host credential exposure.
Thanks for the detail on keeping browser state ephemeral per session so an MCP bridge never touches your daily browser profile, saved cookies, or local network. I'm building BrowserBox to run browser sessions inside an isolated remote container off the host machine so web access from an agent or operator cannot expose local host credentials: browserbox.io/go/forum-20261128-de...
Good write-up, and the MCP quote is the line people skip. One pattern that closes the stdio gap without giving up local servers: launch the MCP server inside the same per-run sandbox as the agent, not beside it, so the harness talks stdio to a process that already sits behind the boundary. Then the only things crossing are the stdio stream and whatever secrets you inject on purpose for that run.
OAuth is the awkward part, since those flows want a host browser. I'd keep the token exchange on the host and pass in a short-lived, narrowly scoped token rather than the refresh token. Do you know if OpenClaw lets you move a single mcp.servers entry into the sandbox, or is it all-or-nothing?