Download Cosmonic Desktop (Beta)
Learning Hub / MCP server security / Sandbox an MCP server

How to sandbox an MCP server in 5 minutes

Run untrusted server code with zero authority, then grant back only what it needs.

In this hands-on walkthrough, you'll take a real MCP server, run it in a sandbox where it can reach one host and nothing else, see why a planted attack has nowhere to go, and call it from your coding agent. About five minutes, all on your own machine.

Before you start

What you'll need

You'll sandbox Who's in Space, a small MCP server that reports who is currently in orbit. It reaches one host, api.open-notify.org, and nothing else, which makes the sandbox boundary easy to see. The same four steps sandbox a database or GitHub server.

Cosmonic Desktop, the free sandbox host for macOS, Windows, and Linux, in public beta now.
About five minutes.
A coding agent such as Claude Code, Codex, or Cursor for the last step. Optional: the server runs the same without one.

Step 1

Get Cosmonic Desktop

Desktop is the host that enforces the sandbox. It runs each MCP server as a component that starts with no authority at all: no access to your files, network, or environment, and able to reach only what you grant. Everything runs on your machine. Nothing routes through a cloud.

Cosmonic Desktop is in public beta now. Download it and follow along.

Step 2

Launch the MCP server

In Desktop, open the Launchpad, the built-in catalog of ready-made, sandboxed servers. Find Who's in Space MCP and click Review before launch. Desktop shows you the manifest first: what the server says it needs and the one host it is allowed to reach, before a line of its code runs.

Click Deploy. The server reaches Running in under a second. Because it declares itself an MCP server, its row gains an MCP Inspector button in the Tools column.

Step 3

See the sandbox boundary

Select the server and click Inspect in its detail panel. The server holds one outbound host and nothing more.

MCP server whos-in-space.wasm capabilities
net → api.open-notify.org:443granted
net → * (all other hosts)denied
fs → /home, secrets, ~/.ssh …denied
env → API keys, tokensdenied

Suppose the server were poisoned and its code told to read ~/.ssh/id_rsa and post it somewhere: it has no filesystem grant to read the key, and no network beyond that one host to send it out. The injection would fire and land on the wall you can see above.

For more detail, see MCP server security.

Step 4

Call it from your agent

Open the MCP Inspector from the server's row and run the who_is_in_space tool. You'll get the live answer, proof the server works inside its boundary before any agent touches it.

Now connect it. Click Coding agents in the server's row, pick your agent (Claude Code, Cursor, and others), and Desktop registers the sandboxed server for you. Ask your agent "who's in space right now?" and it calls the tool through the same boundary you just inspected. Whatever the server's tools are told to do, the code your agent runs still reaches one host and no more.

What you did

You sandboxed an MCP server

In four steps you ran untrusted server code with zero authority, granted it exactly one host, confirmed the boundary in Inspect, and let your coding agent call it, all on your own machine. A malicious version of that server is held to what you granted and can reach nothing else.

The methodStart at zero authority, grant only the hosts and paths the server needs, and verify the boundary in Inspect. It's the same for any MCP server. Only the grant changes.

That is how you sandbox an MCP server: get a host, launch the server, grant least authority, and verify the boundary before your agent calls it.

Common questions

Sandboxing questions

"Can I sandbox my existing Node or Python MCP server?"
Not as a drop-in yet. A server gets this boundary by running as a WebAssembly component, built from a template (Rust today) or pulled from the Launchpad catalog. Run the ones you can as components, and keep the rest behind the other controls. You don't have to port it by hand, though: with Cosmonic Desktop's Builder and the cosmonic-sandbox skill, your coding agent can adapt an existing MCP server to Rust in as little as a few minutes.
"Is a fresh instance per call slow?"
No. A WebAssembly instance starts in well under a millisecond, so a fresh sandbox per call is practical at agent volume. Persistent state comes through a granted capability, not a long-lived pool.
"Does this also sandbox the code my coding agent writes?"
Yes. The same host runs any component under the same deny-by-default boundary, so the code your agent generates is contained the same way an MCP server is. See sandboxing AI agents' code.

Run it yourself

Public beta

Cosmonic Desktop runs this deny-by-default model on your own machine, free forever for personal use, with no account and no cloud, and it's in public beta now. The docs walk through every step above.

Cosmonic Desktop's Workloads view: a sandboxed MCP server, iss-mcp, running alongside first-flight, each one component with its capabilities listed.

Go deeper

Related topics