|
| 1 | +# Node-code-sandbox MCP Server |
| 2 | + |
| 3 | +A Node.js–based Model Context Protocol server that spins up disposable Docker containers to execute arbitrary JavaScript. |
| 4 | + |
| 5 | +[What is an MCP Server?](https://www.anthropic.com/news/model-context-protocol) |
| 6 | + |
| 7 | +## Characteristics |
| 8 | +Attribute|Details| |
| 9 | +|-|-| |
| 10 | +**Image Source**|Official Image |
| 11 | +**Docker Image**|[mcp/node-code-sandbox](https://hub.docker.com/repository/docker/mcp/node-code-sandbox) |
| 12 | +**Author**|[alfonsograziano](https://github.com/alfonsograziano) |
| 13 | +**Repository**|https://github.com/alfonsograziano/node-code-sandbox-mcp |
| 14 | +**Dockerfile**|https://github.com/alfonsograziano/node-code-sandbox-mcp/blob/master/Dockerfile |
| 15 | +**Docker Image built by**|Docker Inc. |
| 16 | +**Docker Scout Health Score**|  |
| 17 | +**Verify Signature**|`COSIGN_REPOSITORY=mcp/signatures cosign verify mcp/node-code-sandbox --key https://raw.githubusercontent.com/docker/keyring/refs/heads/main/public/mcp/latest.pub` |
| 18 | +**Licence**| |
| 19 | + |
| 20 | +## Available Tools |
| 21 | +Tools provided by this Server|Short Description |
| 22 | +-|- |
| 23 | +`get_dependency_types`|Given an array of npm package names (and optional versions), |
| 24 | + fetch whether each package ships its own TypeScript definitions |
| 25 | + or has a corresponding @types/… package, and return the raw .d.ts text.| |
| 26 | +`run_js`|Install npm dependencies and run JavaScript code inside a running sandbox container.| |
| 27 | +`run_js_ephemeral`|Run a JavaScript snippet in a temporary disposable container with optional npm dependencies, then automatically clean up.| |
| 28 | +`sandbox_exec`|Execute one or more shell commands inside a running sandbox container.| |
| 29 | +`sandbox_initialize`|Start a new isolated Docker container running Node.js.| |
| 30 | +`sandbox_stop`|Terminate and remove a running sandbox container.| |
| 31 | + |
| 32 | +--- |
| 33 | +## Tools Details |
| 34 | + |
| 35 | +#### Tool: **`get_dependency_types`** |
| 36 | +Given an array of npm package names (and optional versions), |
| 37 | + fetch whether each package ships its own TypeScript definitions |
| 38 | + or has a corresponding @types/… package, and return the raw .d.ts text. |
| 39 | + |
| 40 | + Useful whenwhen you're about to run a Node.js script against an unfamiliar dependency |
| 41 | + and want to inspect what APIs and types it exposes. |
| 42 | +Parameters|Type|Description |
| 43 | +-|-|- |
| 44 | +`dependencies`|`array`| |
| 45 | + |
| 46 | +--- |
| 47 | +#### Tool: **`run_js`** |
| 48 | +Install npm dependencies and run JavaScript code inside a running sandbox container. |
| 49 | + After running, you must manually stop the sandbox to free resources. |
| 50 | + The code must be valid ESModules (import/export syntax). Best for complex workflows where you want to reuse the environment across multiple executions. |
| 51 | + When reading and writing from the Node.js processes, you always need to read from and write to the "./files" directory to ensure persistence on the mounted volume. |
| 52 | +Parameters|Type|Description |
| 53 | +-|-|- |
| 54 | +`code`|`string`|JavaScript code to run inside the container. |
| 55 | +`container_id`|`string`|Docker container identifier |
| 56 | +`dependencies`|`array` *optional*|A list of npm dependencies to install before running the code. Each item must have a `name` (package) and `version` (range). If none, returns an empty array. |
| 57 | +`listenOnPort`|`number` *optional*|If set, leaves the process running and exposes this port to the host. |
| 58 | + |
| 59 | +--- |
| 60 | +#### Tool: **`run_js_ephemeral`** |
| 61 | +Run a JavaScript snippet in a temporary disposable container with optional npm dependencies, then automatically clean up. |
| 62 | + The code must be valid ESModules (import/export syntax). Ideal for simple one-shot executions without maintaining a sandbox or managing cleanup manually. |
| 63 | + When reading and writing from the Node.js processes, you always need to read from and write to the "./files" directory to ensure persistence on the mounted volume. |
| 64 | + This includes images (e.g., PNG, JPEG) and other files (e.g., text, JSON, binaries). |
| 65 | + |
| 66 | + Example: |
| 67 | + ```js |
| 68 | + import fs from "fs/promises"; |
| 69 | + await fs.writeFile("./files/hello.txt", "Hello world!"); |
| 70 | + console.log("Saved ./files/hello.txt"); |
| 71 | + ``` |
| 72 | +Parameters|Type|Description |
| 73 | +-|-|- |
| 74 | +`code`|`string`|JavaScript code to run inside the ephemeral container. |
| 75 | +`dependencies`|`array` *optional*|A list of npm dependencies to install before running the code. Each item must have a `name` (package) and `version` (range). If none, returns an empty array. |
| 76 | +`image`|`string` *optional*|Docker image to use for ephemeral execution. e.g. - **node:lts-slim**: Node.js LTS version, slim variant. (Lightweight and fast for JavaScript execution tasks.) |
| 77 | +- **mcr.microsoft.com/playwright:v1.52.0-noble**: Playwright image for browser automation. (Preconfigured for running Playwright scripts.) |
| 78 | +- **alfonsograziano/node-chartjs-canvas:latest**: Chart.js image for chart generation and mermaid charts generation. ('Preconfigured for generating charts with chartjs-node-canvas and Mermaid. Minimal Mermaid example: |
| 79 | + import fs from "fs"; |
| 80 | + import { run } from "@mermaid-js/mermaid-cli"; |
| 81 | + fs.writeFileSync("./files/diagram.mmd", "graph LR; A-->B;", "utf8"); |
| 82 | + await run("./files/diagram.mmd", "./files/diagram.svg");) |
| 83 | + |
| 84 | +--- |
| 85 | +#### Tool: **`sandbox_exec`** |
| 86 | +Execute one or more shell commands inside a running sandbox container. Requires a sandbox initialized beforehand. |
| 87 | +Parameters|Type|Description |
| 88 | +-|-|- |
| 89 | +`commands`|`array`| |
| 90 | +`container_id`|`string`| |
| 91 | + |
| 92 | +--- |
| 93 | +#### Tool: **`sandbox_initialize`** |
| 94 | +Start a new isolated Docker container running Node.js. Used to set up a sandbox session for multiple commands and scripts. |
| 95 | +Parameters|Type|Description |
| 96 | +-|-|- |
| 97 | +`image`|`string` *optional*| |
| 98 | +`port`|`number` *optional*|If set, maps this container port to the host |
| 99 | + |
| 100 | +--- |
| 101 | +#### Tool: **`sandbox_stop`** |
| 102 | +Terminate and remove a running sandbox container. Should be called after finishing work in a sandbox initialized with sandbox_initialize. |
| 103 | +Parameters|Type|Description |
| 104 | +-|-|- |
| 105 | +`container_id`|`string`| |
| 106 | + |
| 107 | +--- |
| 108 | +## Use this MCP Server |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | + "mcpServers": { |
| 113 | + "node-code-sandbox": { |
| 114 | + "command": "docker", |
| 115 | + "args": [ |
| 116 | + "run", |
| 117 | + "-i", |
| 118 | + "--rm", |
| 119 | + "mcp/node-code-sandbox" |
| 120 | + ] |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +[Why is it safer to run MCP Servers with Docker?](https://www.docker.com/blog/the-model-context-protocol-simplifying-building-ai-apps-with-anthropic-claude-desktop-and-docker/) |
0 commit comments