The practical answer
If you are adding a community or customer-contributed MCP server to a product, treat it as untrusted code—not as an ordinary API dependency. Run it inside an isolated execution environment, give it only the files and network destinations required for the task, provide credentials through a narrow mechanism rather than a general-purpose secret store, and validate its inputs and outputs before the results reach the agent or a customer system.
This does not require an enterprise security team. A small team can begin with containers, per-server configuration, restricted service accounts, an explicit network policy, and a validation layer between the MCP server and the application. The important point is that one boundary must hold even if the model behaves incorrectly, the tool description is malicious, or the server package itself is compromised.
Why a normal container is not enough
An MCP server may appear harmless because it is advertised as a filesystem helper, issue tracker, or data connector. But an MCP client exposes its tool descriptions and results to the model, and the server can execute code on its behalf. A compromised server could read unrelated files, open outbound connections, leak an injected credential, or return content that tries to redirect the agent into making another unsafe call.
The practical risks include:
- Prompt injection through tool data: Files, issue comments, search results, and tool return values can contain instructions aimed at the model.
- Tool poisoning: A tool description or schema can present itself as safe while encouraging harmful behavior.
- Over-broad filesystem access: A tool intended for one project directory may be able to read home directories, SSH material, or other customers’ workspaces.
- Network exfiltration: A server with unrestricted egress can send local data to an external host.
- Credential misuse: A server given broad cloud credentials may use them well beyond the requested operation.
- Cross-server influence: A malicious server can try to influence how the agent uses tools exposed by another server.
Sandboxing does not make these risks disappear. It limits the damage when a control fails and gives you a place to enforce authorization that the model cannot override.
Start with the trust boundary, not the container
Before choosing software, draw the boundary around the untrusted MCP server. A typical deployment has these layers:
- The agent or MCP client chooses a tool and supplies arguments.
- A policy layer checks whether the call and its arguments are allowed.
- The MCP server runs in a restricted sandbox.
- The server reads or writes only approved resources.
- Its output passes schema and content checks before being returned to the agent.
That structure matters because a sandbox controls the server process, while a policy layer controls what the agent is allowed to request. You need both. A read-only filesystem, for example, prevents certain writes but does not stop a server from returning sensitive content or making an outbound request.
For a solo developer, this can remain small:
- One container or equivalent isolated runtime per MCP server.
- One mounted workspace per task or tenant.
- A dedicated low-privilege identity for downstream APIs.
- An outbound allowlist for required services.
- A wrapper that validates MCP arguments and results.
- Logs containing the server identity, tool name, decision, and duration.
The exact runtime matters less than whether the boundaries are explicit and testable.
Step 1: Decide what the server is allowed to do
Create a short capability manifest for every MCP server. Do not begin with what the server says it can do; begin with what your product actually needs it to do.
For each tool, record:
- The business action it performs.
- The files or directories it may access.
- The downstream services it may contact.
- The credentials it receives.
- Whether it changes state.
- Whether a human approval is required.
- The maximum output size and expected response format.
Then compare the server’s advertised capabilities with that manifest. If your product only needs to search one repository, do not grant general home-directory access because another tool in the same server advertises filesystem operations. If a connector only needs to create a ticket, do not give it permission to delete tickets.
A useful founder-level rule is: one server, one intended job, one narrow data boundary. If one package exposes several unrelated capabilities, run it as several configurations or isolate the specific tool behind your own wrapper.
Step 2: Isolate tool execution
Put the MCP server in a sandbox that limits what its process can reach. For a container-based deployment, the important controls are:
- Run as a non-root user.
- Use a read-only root filesystem where practical.
- Mount only task-specific directories as writable.
- Drop unnecessary Linux capabilities.
- Disable privilege escalation.
- Apply CPU, memory, process, and execution-time limits.
- Do not mount the Docker socket, host SSH agent, cloud metadata service, or broad home directories.
- Restart or discard the environment after use when state is not required.
A minimal policy should look like this:
server: community-example
+network: false
+cap_drop:
+ - ALL
+security_opt:
+ - no-new-privileges:true
+read_only: true
+tmpfs:
+ - /tmp:size=64m,noexec,nosuid
+mem_limit: 256m
+pids_limit: 128
+volumes:
+ - /srv/mcp-jobs/job-123:/workspace:rw
+environment:
+ MCP_JOB_ID: job-123
+```
This example is a policy sketch, not a complete production configuration. Exact runtime fields vary. The design is the point: no network by default, no writable host locations, constrained resources, and a disposable workspace.
A read-only container is not enough if the mounted workspace contains sensitive files. Mount only the files required for the current operation, and copy them into the sandbox when the operation permits it. Avoid giving the server access to a parent directory containing unrelated customer data.
### Local subprocesses need the same discipline
MCP servers commonly communicate with a client over standard input and output, which means the client launches the server as a local process. If you use this transport, do not let the process inherit your developer's full environment or home directory. Use a dedicated working directory, a minimal environment, resource limits, and an explicit allowlist of required files.
The goal is not to make local development cumbersome. It is to avoid a convenient default that silently turns a third-party server into a reader of everything you can read.
## Step 3: Separate filesystem access from network access
Filesystem and network isolation solve different problems, so manage them separately.
### Filesystem isolation
Use a hierarchy such as:
```text
+/var/lib/mcp/servers/community-example/
+ config/ read-only configuration
+ workspaces/ per-job or per-tenant workspaces
+ outputs/ bounded result directory
+ tmp/ ephemeral temporary files
+```
Then enforce rules such as:
- Normalize and resolve paths before opening them.
- Reject paths that escape the approved root.
- Do not follow symlinks outside that root.
- Separate input and output directories.
- Delete temporary data after the job unless it is required for audit or customer delivery.
- Treat downloaded files as untrusted content, including archives and symbolic links.
MCP Roots can help a client communicate which directories are in scope, but they are not automatically a kernel-level filesystem boundary. Enforce the restriction again inside the server or sandbox. Do not treat an advisory root declaration as sufficient containment.
### Network isolation
Default to no outbound network. Add access only when a specific tool requires it.
A network policy should identify destinations by service and purpose, not merely by a broad domain category. For example, a connector that creates a GitHub issue might need access to the GitHub API, but it does not need arbitrary web browsing. If the server shells out to a command-line client, the sandbox must still prevent that client from reaching unrelated hosts.
Be careful with proxy and DNS controls. Blocking direct connections while leaving a permissive proxy open can create the appearance of network isolation without providing it. Test the actual process and its child processes, because malicious code commonly attempts to create its own network client.
## Step 4: Inject secrets narrowly
Do not put long-lived credentials in the MCP server image, a checked-in configuration file, or the model's context. Those approaches make rotation, revocation, and attribution difficult.
For an independent product, a practical sequence is:
1. Store the credential in an encrypted secret manager.
2. Give each MCP server or tenant a dedicated credential.
3. Fetch or mount the credential only at runtime.
4. Scope it to the smallest downstream permission that works.
5. Rotate and revoke it independently of the server package.
6. Avoid logging the credential or full authorization headers.
If you cannot operate a secret manager, a temporary credential broker or narrowly scoped wrapper is still better than exporting an entire secret store into the sandbox. The wrapper can hold the real token and pass only the authorization needed for one tool call.
Avoid giving a server a general-purpose cloud credential with permission to create arbitrary infrastructure, read broad storage, or modify IAM policy. If the server talks to a third-party service, use that service's scoped token or app authorization where possible. The MCP server should not become a permanent superuser.
Secrets also need directionality. For example, the agent may request that a message be sent, but it should not be able to read the messaging account's stored credentials or token inventory. If a tool requires both inbound and outbound privileges, split those capabilities rather than exposing one all-or-nothing secret.
## Step 5: Validate before returning results
Sandboxing limits what a server can access; validation determines whether its answer is safe for the agent and the product to use.
Validate at three layers:
### Validate tool arguments
Use the server's declared schema, then add product-specific constraints. A string field may need an allowlist, a path must resolve inside an approved directory, and a record identifier must belong to the current tenant. Reject unknown fields where the downstream integration allows it.
### Validate the actual side effect
A schema can prove that a parameter has the expected shape; it cannot prove that the server performed the intended action. When a tool changes external state, confirm the result with a trusted API or application-owned service where feasible. This is especially important for high-impact actions such as deleting records, sending messages, or spending money.
### Validate returned content
Tool results are untrusted input, including apparently harmless strings. Apply output-size limits, expected content types, and strict schemas for machine-readable results. If a result is displayed to a user, strip active content according to the output context. If the result is fed back to the model, keep it clearly separate from trusted instructions.
Do not attempt to solve prompt injection with a single keyword filter. Pattern matching can miss obfuscated instructions and may falsely alter legitimate customer content. Use it only as one signal, alongside scoped permissions, isolation, approval gates, and output validation.
### Require approval for consequential actions
Use human-in-the-loop approval for irreversible or externally visible actions when the cost of a mistake is greater than the delay. Examples include deleting customer data, publishing public content, changing production configuration, transferring funds, or sending messages to a large audience.
The approval prompt should show the intended action, target, and key arguments. Do not ask a user to approve an opaque action described only as “use the integration.”
## Step 6: Add a small validation wrapper
You do not need a large gateway to obtain useful controls. A wrapper can sit between the MCP client and the server, enforce a per-tool policy, and exchange credentials without passing them to the model.
The basic flow is:
```text
+agent request
+ -> policy decision
+ -> allowed server in sandbox
+ -> validated result
+ -> agent or application
+```
A wrapper should perform the following steps:
1. Identify the server and tool from an allowlist.
2. Validate the request against a product-owned schema.
3. Reject calls requiring unavailable scopes.
4. Start or select an isolated runtime for the server.
5. Provide only task-specific mounts and temporary credentials.
6. Capture the result within size and time limits.
7. Validate the result and record an audit event.
8. Release temporary credentials and discard ephemeral state.
Keep the allowlist in product-controlled configuration rather than accepting any server definition supplied at runtime. A server's tool list should never be the authority that decides which tools your application may call.
## Step 7: Test the boundary, not just the happy path
Normal tests prove that a tool works. Security tests should try to make the sandbox violate its contract.
A minimum test set for an untrusted MCP server includes:
- Read a secret file outside its mounted workspace.
- Write outside its writable directory.
- Follow a symlink that points outside the workspace.
- Connect to an unapproved network destination.
- Resolve a domain or address outside the intended service.
- Spawn a child process that attempts the same actions.
- Exhaust memory, process count, or execution time.
- Return malformed, oversized, or unexpected output.
- Include instruction-like text in a tool result.
- Request a tool or scope that the current task does not need.
- Attempt to reuse a temporary credential after the task ends.
Also test the wrapper's decision path. A sandbox can be correctly configured while the application still permits the wrong tool call. Record both the attempted action and the enforcement point that stopped it.
## A minimum viable deployment for a small team
If you need to ship quickly, use this order:
1. **Inventory the server's required capabilities.** Record files, services, credentials, and state-changing tools.
2. **Pin and review the exact server build.** Do not run an unpinned community branch in production.
3. **Run one server per isolated runtime.** Avoid sharing writable workspaces between tenants or jobs.
4. **Start with outbound network disabled.** Add only the destinations required by the tool.
5. **Mount a narrow workspace.** Use a dedicated service account and a read-only root filesystem.
6. **Put credentials behind a broker.** Issue temporary, least-privilege credentials per job or tenant.
7. **Validate arguments and results in product code.** Keep sensitive state changes behind an approval or trusted confirmation step.
8. **Log decisions and tool calls.** Include server version, tool, tenant, policy result, and timing without logging secrets.
9. **Run adversarial boundary tests.** Repeat them when the server version or isolation policy changes.
+
+This setup will not provide the strongest possible isolation, and it may not support servers that legitimately require broad access. That is the trade-off to make deliberately. Start restrictive, add one justified exception at a time, and record why it is necessary.
+
+## Decisions to make before launch
+
+As a founder, I would resolve four commercial questions before adding many community servers:
+
+### Can you support untrusted servers at all?
+
+If your product promises to run arbitrary customer code, that is a hosting and security commitment, not merely an MCP feature. The workload may require dedicated isolation, stronger resource controls, abuse monitoring, and an incident process.
+
+### Who bears the operational cost of isolation?
+
+Containers, secret management, logs, and validation all add time and compute. Put a practical ceiling on per-job runtime, storage, and network usage. If the economics do not support that ceiling, narrow the advertised capabilities instead of removing controls in production.
+
+### Is a wrapper worth building?
+
+For one local, low-risk server, a product-owned wrapper may be excessive. For customer-facing agents or third-party servers, it is often the simplest place to enforce schemas, inject secrets, require approvals, and record audit events.
+
+### Can you disable a server quickly?
+
+Keep a kill switch that blocks a server version, tenant, or tool without taking down unrelated workflows. This matters for both security incidents and abandoned dependencies. For broader lifecycle guidance, see [When an MCP Server Goes Stale: A Solo Founder's Decision Guide](/en/detecting-stale-mcp-servers-solo-founder/).
+
+## What sandboxing does not solve
+
+Sandboxing is not a substitute for:
+
+- Correct authentication and authorization in the MCP server.
+- Short-lived, narrowly scoped credentials.
+- Stable server identity and a trusted distribution source.
+- Validation of tool arguments and returned data.
+- Human approval for consequential actions.
+- Monitoring and a way to revoke access.
+
+Those controls work together. If the sandbox is strong but authorization is broken, the server can still perform unauthorized work inside its boundary. If authorization is narrow but the process is not isolated, a malicious implementation can misuse the authority it was given.
+
+For customer-facing access, the next layer is deciding how credentials are delegated and revoked; the related guide [How to Choose an MCP Server Authorization Model Without Handing Agents Too Much Access](/en/mcp-authorization-model-decision-framework/) covers that decision in more depth.
+
+## FAQ
+
+### Should I run every MCP server in a container?
+
+Containers are a practical isolation mechanism, but they are not the entire policy. A container with broad mounts, excessive credentials, and unrestricted networking may provide little meaningful protection. Review the runtime boundary and the server's authorization together.
+
+### Is a read-only container enough for filesystem tools?
+
+No. The server may still need a small writable workspace, and it may be able to read sensitive data through allowed mounts or return sensitive information to the agent. Use narrow, per-job mounts and validate the results.
+
+### How do I stop a server from stealing an injected secret?
+
+You cannot make a compromised process fully trustworthy. Limit the secret's scope and lifetime, prevent unnecessary network egress, avoid exposing it to the model, and use a broker when possible. Assume anything given directly to a compromised server may be misused.
+
+### Is blocking tool descriptions and results for prompt injection practical?
+
+Not as a complete defense. Embedded instructions can be subtle, and ordinary business content may resemble an instruction. Use isolation, narrow permissions, explicit trust boundaries, output validation, and approvals as the primary controls. Treat content inspection as an additional signal rather than a guarantee.
+
+## The bottom line
+
+For an indie developer, the defensible MCP architecture is not a giant security platform. It is a narrow path between the agent and an untrusted server: one isolated runtime, one purpose-built workspace, one explicit network policy, one temporary least-privilege credential, and one validation layer.
+
+Start there. Then test whether the boundary holds. That is enough to support community servers responsibly while keeping customer data, infrastructure credentials, and your ability to operate the product outside the blast radius of one bad tool call.
+
+## Sources
+
+- [Security Best Practices - Model Context Protocol](https://modelcontextprotocol.io/docs/draft/tutorials/security/security_best_practices)
+- [MCP Security - OWASP Cheat Sheet Series](https://cheatsheetseries.owasp.org/cheatsheets/MCP_Security_Cheat_Sheet.html)
+- [Sandboxing in MCP](https://www.dailydoseofds.com/model-context-protocol-crash-course-part-7)
+- [Securing the Model Context Protocol (MCP): Risks, Controls, and Governance](https://arxiv.org/html/2511.20920v1)
+







