# Run an MCP server in a sandbox

Keep an MCP server away from your files by running it in a Linux sandbox.

Requires [OSMates Pro](https://osmates.com/docs/editions#what-pro-adds).

## Make the sandbox

An MCP server your client starts on your Mac runs as you. It can read your SSH keys and tokens. Claude Code runs these servers [outside its sandbox, with your full access](https://code.claude.com/docs/en/sandboxing#what-runs-outside-the-sandbox).

1. Make a Linux machine for the server and open a shell in it:

```sh
osmates vm create mcp-base --image debian-13
osmates vm start mcp-base --wait agent
osmates ssh mcp-base
```

2. Install the server as its instructions say, then run `exit`.
3. Stop the machine, then clone and start a sandbox:

```sh
osmates vm stop mcp-base
osmates vm clone mcp-base mcp --preset agent-sandbox
osmates vm start mcp --wait agent
```

Start `mcp` before your client. When it stops, it's deleted with everything the server wrote. Clone it again for your next session.

## Allow another host

The sandbox reaches package registries, GitHub, and model APIs. If the server needs another host:

```sh
osmates vm egress mcp --allow api.example.com
```

To keep a rule for every sandbox, set it on `mcp-base` before you clone. A source with its own rules passes on only those, so add the presets too:

```sh
osmates vm egress mcp-base --mode allowlist --allow preset:packages --allow preset:github --allow preset:models --allow api.example.com
```

## Register the server with your client

Your client starts the server with `ssh mcp.osmates -- <command>`, which needs [ssh by name](https://osmates.com/docs/ssh#reach-machines-by-name). Replace `<command>` with the command that starts the server, and `<server>` with a name for it.

### Claude Code

```sh
claude mcp add --transport stdio --scope user <server> -- ssh mcp.osmates -- <command>
```

The first `--` ends Claude Code's options, and the second ends ssh's. With `--scope user`, every project of yours gets the server.

To share the server with everyone on a project, add it to `.mcp.json` at the project's root instead:

```json
{
  "mcpServers": {
    "<server>": {
      "type": "stdio",
      "command": "ssh",
      "args": ["mcp.osmates", "--", "<command>"]
    }
  }
}
```

[Claude Code's MCP documentation](https://code.claude.com/docs/en/mcp) lists the other scopes and settings.

### Codex

```sh
codex mcp add <server> -- ssh mcp.osmates -- <command>
```

Or add the server to `~/.codex/config.toml`:

```toml
[mcp_servers.<server>]
command = "ssh"
args = ["mcp.osmates", "--", "<command>"]
```

[Codex's MCP documentation](https://learn.chatgpt.com/docs/extend/mcp) lists the other settings.
