neu-sandbox-mcp
Official# neu-sandbox-mcp
An MCP server that gives an agent remote sandboxes: start a container from an image, run commands in it, read and write its files, reach the servers it runs, and shut it down.
<p>
<a href="LICENSE"><img alt="License: Apache 2.0" src="https://img.shields.io/badge/License-Apache_2.0-blue.svg"></a>
<a href="CONTRIBUTING.md"><img alt="Contributions welcome" src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg"></a>
</p>
## Why
- **One set of tools across backends.** Prompts and skills keep the same tool names and outputs when sandboxes move to another backend. Each backend is a small adapter behind one interface.
- **Backends differ, and the tools say so.** Sandbox services vary a lot: some take any image and some need it registered first, some keep a background command's output and some only stream it, some previews are public and some need a token. Each backend declares what it supports, and only the tools it can really serve are registered, with descriptions that match. Nothing missing is faked.
- **Credentials stay on the server.** The backend token never enters the agent's context.
- **Safe to share between tenants.** A scope confines every tool to the sandboxes tagged for one tenant, even when tenants share the backend's credentials.
## Tools
The base tools are always there. The rest appear when the backend supports them.
| Tool | What it does | Needs |
| --- | --- | --- |
| `create_sandbox` | Starts a sandbox from an image. Takes `timeout_seconds` and `env`, plus `resource` and `resource_requests` where the backend accepts them. | — |
| `list_sandboxes` | Lists sandboxes in scope. | — |
| `kill_sandbox` | Destroys a sandbox. | — |
| `sandbox_run_command` | Runs a shell command and waits for it. With `background: true`, returns a `command_id` instead. | `background` needs background commands |
| `sandbox_read_file` | Reads a text file, optionally a line range. | — |
| `sandbox_write_files` | Writes text files, creating parent directories. | — |
| `sandbox_renew` | Pushes the expiry further out. | renew |
| `sandbox_get_command_status` | Whether a background command is still running, and its exit code. | background output kept (`cursor` or `snapshot`) |
| `sandbox_get_command_logs` | A background command's output: in increments from a cursor, or its latest tail. | background output kept (`cursor` or `snapshot`) |
| `sandbox_interrupt_command` | Stops a background command. | interrupt |
| `sandbox_list_directory` | Lists a directory, with entry types. | directory listing |
| `sandbox_search_files` | Finds files by glob on the name. | file search |
| `sandbox_replace_contents` | Replaces text in files, reporting a count per file. | replace |
| `sandbox_move_files` / `sandbox_delete_files` / `sandbox_create_directories` / `sandbox_delete_directories` | File management. | each its own |
| `sandbox_get_preview_url` | A URL that reaches a port inside the sandbox. | a `public` or `signed` preview |
## Backends
| Backend | Image | Timeout (default / max) | Background output | Preview | Metadata | Renew | List dir | Search | Replace |
| --- | --- | --- | --- | --- | :---: | :---: | :---: | :---: | :---: |
| [`nap`](https://github.com/neutree-ai/agent-platform) | any, entrypoint override | 1 hour / none | cursor | public (when configured) | ✅ | ✅ | ✅ | ✅ | ✅ |
More backends are planned. See [Adding a backend](CONTRIBUTING.md#adding-a-sandbox-backend).
### Capabilities
A backend declares, in `capabilities`, the form its create and lifecycle take:
| Capability | Values |
| --- | --- |
| `image.source` | `any`: any image reference at create time. `registered`: images must be registered with the service first. |
| `image.entrypoint` | `image`: the image's own entrypoint runs. `override`: create can replace it. `none`: nothing runs until you start it. |
| `resources` | `perSandbox`: limits can be chosen at create time. `requests`: requests can be set apart from limits. |
| `timeout` | `absolute` (from creation) or `idle` (since last activity), with the default and the maximum. |
| `metadata` | Sandboxes can be tagged and listed by tag. Required for a scope. |
Everything else is an optional member of the provider, present only when the backend has it. A member that comes in several forms carries its `kind`:
| Member | `kind` |
| --- | --- |
| `commands` (background commands) | `cursor`: output is read in increments from a byte offset. `snapshot`: each read returns the whole log. `stream`: output is only seen while attached, so it cannot be read later. |
| `preview` (reaching a port) | `public`: the URL works as is. `signed`: a browser-openable URL that expires. `header`: requests must carry headers, so it serves servers, not people. |
`renew`, `commands.interrupt` and each file operation beyond read and write are simply present or absent.
Sandbox `status` is one of `creating`, `running`, `paused`, `stopped`, `failed` or `unknown`; each backend maps its own states onto these.
## Run it as a server
Requires Node.js 22 or newer. The server speaks MCP over stdio.
```json
{
"mcpServers": {
"sandbox": {
"command": "npx",
"args": ["-y", "neu-sandbox-mcp"],
"env": {
"NEU_SANDBOX_BACKEND": "nap",
"NAP_SANDBOX_URL": "https://sandbox.example.com",
"NAP_SANDBOX_TOKEN": "<token>",
"NAP_SANDBOX_PUBLIC_URL": "https://sandbox.example.com"
}
}
}
}
```
`NEU_SANDBOX_BACKEND` picks the backend and defaults to `nap`. Each backend then reads its own variables.
**`nap`**
| Variable | Meaning |
| --- | --- |
| `NAP_SANDBOX_URL` | Base URL of the sandbox service API. Required. |
| `NAP_SANDBOX_TOKEN` | Bearer token for the sandbox service. Required. |
| `NAP_SANDBOX_PUBLIC_URL` | Public URL of the sandbox service, whose host fronts the preview subdomains (`<id>-<port>.<host>`). Without it there is no preview tool. |
## Use it as a library
To add the tools to an MCP server you already run, register them on it:
```ts
import { McpServer } from '@modelcontextprotocol/server'
import { createNapProvider, registerSandboxTools } from 'neu-sandbox-mcp'
const server = new McpServer({ name: 'my-server', version: '1.0.0' })
registerSandboxTools(server, {
provider: createNapProvider({
baseUrl: 'http://sandbox.internal:3006',
previewBaseUrl: 'https://sandbox.example.com',
token: async () => lookUpTokenFor(tenant),
}),
scope: { tenant_id: tenant.id },
})
```
The server can come from either generation of the MCP TypeScript SDK: `@modelcontextprotocol/server` (v2) or `@modelcontextprotocol/sdk` (v1).
`scope` is a set of tags that confines the tools to one tenant. Every sandbox they create carries the tags, `list_sandboxes` returns only sandboxes that carry them, and a tool given a sandbox ID refuses it unless that sandbox carries them.
`registerSandboxTools` returns the provider the tools act through, already confined to the scope, so tools you add yourself get the same confinement. The provider is also usable on its own, for example behind your own REST API: wrap it with `scopeProvider(provider, scope)`, and calls on an out-of-scope ID throw `SandboxNotFoundError`. `unsupportedCreateOptions(provider.capabilities, opts)` names create options the backend cannot honour, so your API can refuse them.
To pick the backend from the environment, the way the standalone server does, use `providerFromEnv(process.env)`.
## License
[Apache License 2.0](LICENSE)
TDQS
Scored across 17 tools
Each tool targets a distinct resource+action, and the descriptions actively disambiguate the risky pairs (delete_files vs delete_directories, create_directories vs write_files, sandbox_list_directory vs sandbox_search_files). Minor residual overlap between list_sandboxes and sandbox_list_directory, and between renew and create, but both are clarified in the text. An agent can select correctly without guessing.
14 of 17 tools follow a clear sandbox_<verb>_<noun> pattern (sandbox_read_file, sandbox_move_files, sandbox_delete_directories). The lifecycle trio (list_sandboxes, create_sandbox, kill_sandbox) drops the prefix and inverts to verb_noun, which is a systematic but noticeable deviation. Still highly readable with no chaotic mixing.
17 tools is at the upper edge of comfortable but each one maps to a real capability gap in a sandbox runtime: lifecycle, command execution/streaming, and file operations. Nothing looks like a redundant alias. Slightly heavy, but no obvious removal candidate.
Coverage is strong for the domain: create/list/renew/kill lifecycle, blocking and background command execution with status, cursor-based logs, and interrupt, plus a full file surface (read, write, replace, move, search, list, delete files and directories). Small gaps remain — no single-sandbox detail/inspect call, no host-to-sandbox upload/download, and no permission or attr operations — but agents can work around these via run_command.