
Node.js Sandbox MCP Server
Run arbitrary JavaScript in ephemeral Docker containers with on-the-fly npm dependency installation.
Add to your client
Copy the config for your MCP client and paste it into its config file.
npx -y node-code-sandbox-mcpPaste into ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"node-js-sandbox-mcp-server": {
"command": "npx",
"args": [
"-y",
"node-code-sandbox-mcp"
],
"env": {
"FILES_DIR": "/Users/alfonsograziano/Desktop/node-sandbox",
"SANDBOX_MEMORY_LIMIT": "512m",
"SANDBOX_CPU_LIMIT": "0.75"
}
}
}
}Step-by-step guides: Add to Claude Desktop · Add to Cursor · Add to Windsurf
Before you start
- Docker installed and running on the host machine
- Recommended: pre-pull Docker images such as node:lts-slim, mcr.microsoft.com/playwright:v1.55.0-noble, and alfonsograziano/node-chartjs-canvas:latest
About Node.js Sandbox MCP Server
An MCP server that spins up disposable Docker containers to execute arbitrary JavaScript with on-the-fly npm dependency installation. It supports one-shot ephemeral runs as well as session-based, long-lived sandbox containers, plus a detached mode for running servers and long-lived services. Files written by scripts during ephemeral runs are returned automatically (images as image content, other files as resource content).
Tools & capabilities (6)
run_js_ephemeralRun a one-off JS script in a brand-new disposable container. Creates a fresh container, writes index.js and a minimal package.json, installs the specified dependencies, executes the script, tears down the container, and returns captured stdout. Any files saved during execution are returned automatically (images as image content, others as resource content). Inputs: image (optional, default node:lts-slim), code (required), dependencies (optional array of { name, version }).
sandbox_initializeStart a fresh sandbox container. Inputs: image (optional, default node:lts-slim), port (optional, maps a container port to the host). Output: container ID string.
sandbox_execRun shell commands inside the running sandbox. Inputs: container_id (from sandbox_initialize), commands (array of shell commands). Output: combined stdout of each command.
run_jsInstall npm dependencies and execute JavaScript code in a running container. Inputs: container_id, code (ES modules supported), dependencies (optional array of { name, version }), listenOnPort (optional; leaves the process running and exposes the port to the host in Detached Mode). Output: script stdout or background execution notice.
sandbox_stopTerminate and remove the sandbox container. Input: container_id (from sandbox_initialize). Output: confirmation message.
search_npm_packagesSearch for npm packages by a search term and get their name, description, and a README snippet. Inputs: searchTerm (required), qualifiers (optional: author, maintainer, scope, keywords, not, is, boostExact). Returns up to 5 packages sorted by popularity, each with name, description, and first 500 characters of the README.
When to use it
- Quick, atomic JavaScript experiments with no manual teardown via ephemeral one-shot runs
- Long-lived sandbox sessions that reuse installed dependencies across multiple scripts
- Generating and returning files (e.g. QR codes, charts, images) from executed scripts
- Spinning up servers or long-lived services on the fly and exposing endpoints via Detached Mode
- Discovering npm packages by search term before installing and using them
Security notes
Executes arbitrary JavaScript and shell commands inside Docker containers. The recommended configuration mounts the Docker socket (/var/run/docker.sock) into the server container, which grants broad control over the host Docker daemon. Containers run with controlled CPU/memory limits (configurable via SANDBOX_MEMORY_LIMIT and SANDBOX_CPU_LIMIT). Docker must be installed and running on the host.
Node.js Sandbox MCP Server FAQ
What do I need to run this server?
Docker must be installed and running on your machine. It is recommended to pre-pull any Docker images you'll need (e.g. node:lts-slim) to avoid delays during first execution.
How do I get generated files back?
Simply save files during your script execution. In the run_js_ephemeral tool, images (PNG, JPEG) are returned as image content and other files (.txt, .json) as resource content. The file saving feature is currently available only in the ephemeral tool.
Can I run a long-lived server inside the sandbox?
Yes. Use run_js with the listenOnPort input (Detached Mode) to leave the process running and expose the port to the host, which is useful for spinning up servers or testing endpoints.
Can I limit container resources?
Yes. Containers run with controlled CPU/memory limits, configurable via the optional SANDBOX_MEMORY_LIMIT and SANDBOX_CPU_LIMIT environment variables.
Alternatives to Node.js Sandbox MCP Server
Compare all alternatives →Microsoft's official browser-automation MCP using Playwright's accessibility tree (no vision model).
Up-to-date, version-specific library documentation injected into your coding agent.
LSP-powered coding agent toolkit: semantic symbol search, references and structural edits.
Compare Node.js Sandbox MCP Server with: