{"slug": "you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host", "title": "You put your agent in a sandbox. Your MCP tools still ran on the host.", "summary": "A developer's analysis of 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 changelog, and the ShellBench paper (arXiv:2611.32946)—finds that containerizing an agent does not sandbox its MCP servers: local stdio MCP servers are ordinary host processes spawned outside the agent's container, and OpenClaw's exec tool runs on the gateway host by default. The writeup recommends running stdio servers inside a digest-pinned container with no extra mounts and no network, and verifying effective posture with `openclaw sandbox explain` and `openclaw security audit`. It also notes Claude Code v2.1.332 added a PreSkillShellCommand hook because MCP-served skills bypassed PreToolUse.", "body_md": "You put your agent in a Docker or Podman container, drop Linux capabilities, mount a read-only root, and cut outbound network access.\n\nThen an MCP tool call still reads local environment variables or touches files outside the workspace.\n\nNothing \"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.\n\nThe official [MCP Local Server Security](https://modelcontextprotocol.io/docs/tutorials/security/local-server-security) specification makes the baseline threat model explicit:\n\n*\"Your real security decisions happen before launch: what you install (provenance) and how you run it (isolation). The stdio transport is not a sandbox.\"*\n\nA 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:\n\n`~/.ssh`, `~/.aws`, plain-text client configs).` npx` or `uvx`, transitive dependencies still resolve at install time—whereas pinning a container image by immutable digest (`image@sha256:...`) freezes the entire dependency tree.\nWhere 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.\n\nOpenClaw documents two boundaries operators routinely confuse in [The trust boundary](https://docs.openclaw.ai/start/why-openclaw/the-trust-boundary) and [What gets sandboxed](https://docs.openclaw.ai/gateway/sandboxing/what-gets-sandboxed):\n\n`exec` runs on the gateway host without prompts. Even OpenClaw's local Codex stdio harness defaults to `approvalPolicy: \"never\"` and `sandbox: \"danger-full-access\"` unless explicitly hardened via `tools.exec.mode: \"auto\"` (`workspace-write` + Guardian review) or an active OpenClaw sandbox.`ls`, `read`, `write`, `edit`, `apply_patch`, `process`, and the optional sandboxed browser run inside the sandbox.` mcp.servers` definitions, shared OAuth flows, `SecretRefs`, and `stdio` child processes. Connecting an MCP server routes tool calls through tool policy (`allow` / `deny`), not magically inside your agent's workspace container.\n\n```\n// Hardened OpenClaw + containerized stdio MCP posture (illustrative combined snippet)\n{\n  agents: {\n    defaults: {\n      sandbox: {\n        mode: \"non-main\", // isolate non-main/group sessions in Docker or Podman\n      },\n    },\n  },\n  mcp: {\n    servers: {\n      \"repo-tools\": {\n        // Containerize local stdio servers instead of running bare npx/python on host\n        command: \"docker\",\n        args: [\n          \"run\", \"--rm\", \"-i\",\n          \"--network=none\",\n          \"--read-only\",\n          \"-v\", \"/srv/project-ro:/workspace:ro\",\n          \"ghcr.io/example/mcp-repo@sha256:00000000000000000000000000000000\"\n        ],\n        enabled: true,\n        toolFilter: { include: [\"search_*\", \"read_*\"] }\n      }\n    }\n  }\n}\n```\n\nThen verify the live effective posture instead of assuming config matches runtime:\n\n```\nopenclaw sandbox explain\nopenclaw security audit\n```\n\n`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.\n\n`v2.1.332`: when skills served over MCP bypass `PreToolUse`\nEven if every runtime tool call runs cleanly inside `PreToolUse`, agent extensions created a second execution path **before the turn even begins**.\n\nIn [Claude Code `v2.1.332`](https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md), Anthropic shipped two paired changes:\n\n`server:skill` in the `/` menu).`PreSkillShellCommand`\nWhy 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.\n\nBlocking load-time skill shell injection in `.claude/settings.json`:\n\n```\n{\n  \"hooks\": {\n    \"PreSkillShellCommand\": [\n      {\n        \"matcher\": \"Bash|PowerShell\",\n        \"hooks\": [\n          {\n            \"type\": \"command\",\n            \"command\": \"${CLAUDE_PROJECT_DIR}/.claude/hooks/block-skill-shell.sh\",\n            \"args\": [],\n            \"onFailure\": \"block\"\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\nExiting 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.\n\nFinally, do not expect switching agent harnesses alone to guarantee safety compliance.\n\nIn [ShellBench (`arXiv:2611.32946`)](https://arxiv.org/abs/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**:\n\n`GPT-6 Astra`) and `GPT-6.1 Sol` at ~1/6 token cost).`214 / 531`) recommended a duplicate or incorrect payment.\nModels 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.\n\n`--network=none`, minimal read-only mounts, digest pinning (`@sha256:...`), and per-server scoped tokens—never plaintext config literals.`onFailure: \"block\"` if you enable skills from remote plugins or MCP servers.`openclaw sandbox explain` and `openclaw security audit` after any config or harness update.\nThis 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.\n\n`https://modelcontextprotocol.io/docs/tutorials/security/local-server-security`\n`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`\n`https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md`, `https://code.claude.com/docs/en/hooks#preskillshellcommand`\n`arXiv:2611.32946`):` https://arxiv.org/abs/2611.32946`", "url": "https://wpnews.pro/news/you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host", "canonical_source": "https://dev.to/dhrubojyoti/you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host-4ph", "published_at": "2026-11-27 12:09:16+00:00", "updated_at": "2026-11-27 12:15:22.717538+00:00", "lang": "en", "topics": ["ai-agents", "ai-safety", "agent-protocols", "ai-tools", "developer-tools"], "entities": ["Model Context Protocol", "OpenClaw", "Anthropic", "Claude Code", "ShellBench", "Docker", "Podman"], "also_reported_by": [], "takeaway": "Containerizing the agent does not sandbox its MCP servers—local stdio servers run as host processes—so wrap each server in a digest-pinned container with --network=none and a read-only workspace mount, and verify the live posture with `openclaw sandbox explain` rather than trusting config.", "recommendation": {"advice": "Run local stdio MCP servers inside a digest-pinned container with no network and a read-only workspace mount, then confirm the effective sandbox with `openclaw sandbox explain` and `openclaw security audit`.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host", "markdown": "https://wpnews.pro/news/you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host.md", "text": "https://wpnews.pro/news/you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host.txt", "jsonld": "https://wpnews.pro/news/you-put-your-agent-in-a-sandbox-your-mcp-tools-still-ran-on-the-host.jsonld"}}