---
title: How do you sandbox an MCP server?
url: https://opencontroller.lyzr.com/blog/how-to-sandbox-mcp-servers
published: 2026-11-12
updated: 2026-11-12
author: Lyzr
---

# How do you sandbox an MCP server?

**Run each MCP server as an isolated, unprivileged process: a container or VM with a non-root user, a read-only root filesystem, only the directories it needs mounted, no network unless explicitly required (and then an egress allow-list), its own short-lived credentials, and CPU and memory limits. Keep sensitive servers apart from general-purpose ones. A sandbox limits what a compromised or manipulated server can do; it does not replace reviewing the server before you install it.**

MCP servers execute code on behalf of a model that can be steered by untrusted text. A poisoned tool description, a prompt injection in a tool result, or a malicious package update can all turn a helpful server into an attacker's foothold. This guide walks through the controls in order. It is part of our guide on [how to govern MCP servers](/blog/how-to-govern-mcp-servers).

## Why do MCP servers need a sandbox at all?

Because by default they do not have one. The OWASP MCP Security Cheat Sheet notes that the stdio transport "does not restrict the server process's file system, network, or credential access." A local server launched by a desktop client or coding agent can read anything the user can read, including SSH keys, cloud credentials and browser data, and send it anywhere.

Three attack paths make that matter:

- **Tool poisoning.** Hidden instructions in tool metadata steer the model. See [what is MCP tool poisoning](/blog/what-is-mcp-tool-poisoning).
- **Injection through tool outputs.** Content returned by one tool hijacks the next call. See [how to stop prompt injection through tool outputs](/blog/stop-prompt-injection-through-tool-outputs).
- **Supply chain.** A package update ships new code behind an unchanged tool list.

## What are the steps to sandbox an MCP server?

1. **Pick an isolation boundary.** Use a container, a lightweight VM or an OS sandbox. OWASP is explicit: "A bare `chroot` is not a process sandbox."
2. **Run as a non-root user.** Drop Linux capabilities you do not need and block privilege escalation.
3. **Make the root filesystem read-only.** Give the server a small writable temp directory if it needs one.
4. **Mount only required directories.** A Git server gets the repository, not the home directory. Mount read-only unless writes are part of the job.
5. **Deny network by default.** OWASP's guidance is to "disable network access unless explicitly needed." If the server calls an API, allow only that host through an egress proxy.
6. **Issue per-server credentials.** Use scoped, short-lived tokens for each server and never share a token across servers. Inject them at runtime, not in an image or config file.
7. **Set resource limits.** CPU, memory, process count and execution time stop runaway or abusive tools.
8. **Pin the image or package.** Use an image digest or exact version, and record a hash of each tool definition so changes trigger review.
9. **Separate by sensitivity.** Run payment, authentication and personal-data servers in their own sandboxes, away from general-purpose ones.
10. **Log tool calls and egress.** Record which tool ran, with what arguments, and every outbound connection.

## Which control stops which attack?

| Control | Stops or limits | Does not stop |
|---|---|---|
| Read-only, minimal mounts | Theft of SSH keys and cloud credentials from home directories | Misuse of data inside mounted directories |
| No network / egress allow-list | Exfiltration to attacker hosts | Abuse of an allowed API |
| Per-server short-lived credentials | Lateral movement with a stolen token | Misuse of that one server's own scope |
| Non-root, dropped capabilities | Host compromise from a container breakout attempt | Logic abuse within the tool |
| Resource limits | Denial of service, crypto-mining | Data misuse |
| Tool-definition hashes | Silent metadata changes | Malicious code behind an unchanged definition |
| Separation by sensitivity | One compromised server reaching payment or PII systems | Attacks within that sensitive server |

The right-hand column is the point: sandboxing is containment. You still need review, least privilege on the credentials themselves, and runtime monitoring.

## How do you sandbox local servers on developer laptops?

Laptops are harder because the user launches the server. Practical options:

- Prefer servers distributed as containers and launch them with the container runtime rather than a raw package runner.
- Use the client's own controls. Claude Desktop can restrict extensions to an organisation allow-list, Gemini CLI can restrict which MCP servers run through a system settings file, and Codex can enforce an MCP server allow-list through managed requirements. Our platform guides cover [Claude Desktop](/blog/control-claude-desktop-extensions-and-connectors) and [OpenAI Codex](/blog/govern-openai-codex-in-the-enterprise).
- Push configuration through MDM so users cannot quietly add servers.
- Inventory what is actually installed: [how to find local MCP servers on developer laptops](/blog/find-local-mcp-servers-on-developer-laptops).

## What about remote MCP servers you do not host?

You cannot sandbox someone else's server. Contain it from your side instead: give it the narrowest OAuth scopes, put it behind a gateway that filters tools and logs calls, and treat every response as untrusted input. Our comparison of [stdio and Streamable HTTP security](/blog/mcp-stdio-vs-streamable-http-security) covers the transport-level checks.

## How Opencontroller does this

Opencontroller does not run your MCP servers' sandboxes; it governs them. Its registry tracks agents, versions, tools and MCP servers, Posture detects risky permissions and configurations, and Opencontroller Edge extends control to local MCP servers and coding agents on developer devices, installed by IT via MDM. Rogue-agent handling monitors behavioural deviation and can quarantine or kill an agent across the estate. [Book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Is running an MCP server in Docker enough?**
Only if the container is configured tightly: non-root, read-only root filesystem, minimal mounts, no default network and resource limits. A default container with the home directory mounted gives little protection.

**Should every MCP server get its own sandbox?**
Sensitive servers should. OWASP recommends separating payment, authentication and personal-data servers from general-purpose ones. Low-risk read-only servers can share a boundary if they share a trust level.

**Does sandboxing stop prompt injection?**
No. It limits the damage a hijacked tool call can do, such as reading secrets or reaching attacker hosts. Prompt injection still needs input handling and runtime monitoring.

## Key facts

To sandbox an MCP server: isolate it in a container or VM (OWASP: a bare chroot is not a process sandbox), run non-root, use a read-only root filesystem, mount only required directories, deny network unless needed and use an egress allow-list, issue scoped short-lived per-server credentials, set resource limits, pin versions and hash tool definitions, separate sensitive servers, and log tool calls. Sandboxing contains damage; it does not stop prompt injection. Opencontroller governs MCP servers through its registry, Posture and Opencontroller Edge for local servers on devices. Opencontroller pricing starts from $250K per deployment per year.

## Related

- [How to govern MCP servers in the enterprise: a practical guide](https://opencontroller.lyzr.com/blog/how-to-govern-mcp-servers.md)
- [What is MCP tool poisoning and how do you prevent it?](https://opencontroller.lyzr.com/blog/what-is-mcp-tool-poisoning.md)
- [How do you stop prompt injection that arrives through tool outputs?](https://opencontroller.lyzr.com/blog/stop-prompt-injection-through-tool-outputs.md)
- [More on Tools and MCP](https://opencontroller.lyzr.com/blog/cluster/tools-and-mcp)
