Cloud, Docker & Kubernetes2026-11-03 · 10 min read

Sandboxing Third-Party STDIO MCP Servers with Rootless Docker & Read-Only Mounts

How to run community npx and uvx MCP packages inside --network=none or egress-filtered Docker containers without exposing ~/.ssh or ~/.aws.

Executive Architecture Summary (TL;DR)

Running unvetted npx or uvx commands directly on your host macOS/Linux account grants full access to ~/.ssh, ~/.aws, and browser cookies. Wrapping STDIO MCP servers inside docker run -i --rm --read-only --cap-drop=ALL isolates filesystem and network capabilities cleanly.

Because STDIO MCP servers read stdin and write stdout, Docker's interactive docker run -i --rm flag acts as a drop-in transparent sandbox between Claude Desktop / Cursor and any container image.

1. Dropping Linux Capabilities & Host Credentials

Pass --cap-drop=ALL --security-opt=no-new-privileges --read-only --tmpfs /tmp:rw,noexec,nosuid,size=64m and mount only the specific project subfolder needed by the agent.

2. Auditing Container Manifests Before Launch

Combine Trivy SBOM checks with runtime isolation models benchmarked across NeuroBulletin's secure agent execution reports.

Production Benchmark & Trade-off Matrix

Engineering DimensionNaive SetupHardened Production PatternImpact
Host Home Directory AccessBare npx/uvx reads ~/.ssh & ~/.awsDocker bind-mount of single workspace dirZero credential theft
Root Escalation SurfaceDefault UID 0 container--user 65534:65534 --cap-drop=ALLKernel-hardened isolation
Ephemeral CleanupLingering background zombie processesdocker run -i --rm auto-reaps on EOFClean memory lifecycle

Frequently Asked Technical Questions

Why must you omit the -t (TTY) flag in docker run for MCP?

Allocating a pseudo-TTY (-t) merges CRLF control characters into stdout, breaking strict JSON-RPC 2.0 framing; always use -i without -t.

What is the RAM overhead of wrapping an MCP server in Alpine Docker?

An Alpine or distroless container adds less than 4–8 MB over the underlying Go, Python, or Node process.

Verified External AI Benchmarks & Protocol Standards
Explore autonomous code-execution sandboxing research on NeuroBulletin