Securing Model Context Protocol: Safer Agentic AI with Containers
Running MCP servers via npx on the host with plaintext environment-variable secrets leaves agentic tooling exposed to supply-chain tampering, credential leakage, and attacks such as rug pulls, tool shadowing, and tool poisoning. Containers address part of this through isolation, reproducibility, and verifiable provenance. They should be paired with scoped secret injection, a single MCP Gateway that screens all server-to-client traffic, and separate policies for which servers are trusted versus which a given agent needs. Tool annotations like readOnlyHint and destructiveHint can be enforced at container runtime, and Docker's MCP Catalog and Toolkit package these ideas behind one socat-over-STDIO connection.
Related posts
- Highlights from AWS re:Invent: Supercharging Kiro with Docker Sandboxes and MCP Catalog
Docker mediumAdeptDocker Sandboxes run coding agents like AWS's Kiro inside isolated containers that see only the project directory and none of the host's credentials, while the Docker MCP Toolkit supplies tools through a gateway that injects secrets only into the specific MCP server that needs them. The walkthrough uses `docker sandbox run --mount-docker-socket kiro` (the socket lets Testcontainers integration tests run), points Kiro at the MCP Gateway via a project-level `.kiro/settings/mcp.json`, and uses an AGENTS.md file to have the agent add the GitHub MCP server on demand and remove it afterward to shrink context and cost. The result is a least-privilege, per-container setup. Planned additions include hostname-based network egress limits against prompt-injection exfiltration and organizational governance of allowed MCP servers. Sandboxes are an experimental feature in Docker Desktop 4.50+.
- MCP Horror Stories: The Security Issues Threatening AI Infrastructure
Docker mediumAdeptMCP servers expose AI agents to six recurring vulnerability classes: OAuth discovery flaws (e.g. CVE-2025-6514 in mcp-remote), command injection (reported in 43% of analyzed servers), unrestricted network fetches (33%), file path leakage (22%), tool poisoning (5.5%) and plaintext secret exposure. Each class comes with checks to apply before installing a server, such as avoiding servers that build shell commands from input or take credentials as environment variables. Docker's MCP Gateway is presented as the mitigation, running each server in a container with no-new-privileges, CPU and memory limits, signature verification, L7 network allowlisting via --block-network, secret scanning via --block-secrets and call logging.
- MCP Security: A Developer’s Guide
Docker easyNoviceMCP servers expand what AI agents can do but introduce risks across four categories: misconfigurations and weak defaults, malicious or compromised servers, secret leakage, and prompt injection or tool poisoning. One cited analysis found command injection flaws in 43% of MCP servers examined. Static AppSec tools miss these risks because agent behavior is non-deterministic and models can treat tool descriptions as instructions. The recommended guardrails are to containerize each server with resource and egress limits, route calls through a policy gateway that verifies signatures, enforces allowlists, redacts secrets, runs pre- and post-call interceptors and logs every call, and pin vetted servers by digest. Docker positions its MCP Gateway and MCP Catalog & Toolkit as the implementation.
- Docker MCP Gateway: Open Source, Secure Infrastructure for Agentic AI
Docker mediumAdeptDocker's MCP Gateway, now open source, is a single enforcement point between AI agents and the MCP servers they call, aggregating multiple containerized servers behind one interface and integrating with Docker Compose. The `docker mcp` CLI covers browsing the catalog, storing secrets such as API keys, writing per-server host config, and running gateways that expose chosen servers and a restricted set of tools over transports like SSE. Security interceptors can be switched on at startup to verify container image signatures, block secret-like content in payloads, and log tool calls. It ships in Docker Desktop and works with any community edition of Docker.
- Dynamic MCPs with Docker: Stop Hardcoding Your Agents’ World
Docker mediumAdeptDocker MCP Gateway now exposes primordial tools (mcp-find, mcp-add) that let agents search a curated catalog of 270+ MCP servers, add them to the live session, and trigger OAuth or elicitation flows, instead of hand-editing JSON config and restarting. The gateway can also hide added servers' tool definitions from tools/list so they stay discoverable without bloating the context window. A code-mode tool lets agents write JavaScript that composes tools from several MCP servers inside a Docker sandbox, keeping intermediate results out of the model and cutting per-turn token usage. The features ship in Docker Desktop 4.50 and are on by default, and cagent can expose such agents to ACP-enabled editors like Zed and Neovim.