Skip to content
Back to search

node-code-sandbox-mcp

A Node.js–based Model Context Protocol server that spins up disposable Docker containers to execute arbitrary JavaScript.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/alfonsograziano--node-code-sandbox-mcp/badge.svg)](/listings/alfonsograziano--node-code-sandbox-mcp)

HTML

<a href="/listings/alfonsograziano--node-code-sandbox-mcp"><img src="/api/listings/alfonsograziano--node-code-sandbox-mcp/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

In order to get started with this MCP server, first of all you need to connect it to a client (for example Claude Desktop).

Once it's running, you can test that it's fully working with a couple of test prompts:

- Validate that the tool can run:

  Create and run a JS script with a console.log("Hello World")

This should run a console.log and in the tool response you should be able to see Hello World.

- Validate that you can install dependencies and save files

  Create and run a JS script that generates a QR code for the URL `https://nodejs.org/en`, and save it as `qrcode.png` **Tip:** Use the `qrcode` package.

This should create a file in your mounted directory (for example the Desktop) called "qrcode.png"

Usage with Claude Desktop

Add this to your `claude_desktop_config.json`: You can follow the [Official Guide](https://modelcontextprotocol.io/quickstart/user) to install this MCP server

{
  "mcpServers": {
    "js-sandbox": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "/var/run/docker.sock:/var/run/docker.sock",
        "-v",
        "$HOME/Desktop/sandbox-output:/root",
        "-e",
        "FILES_DIR=$HOME/Desktop/sandbox-output",
        "-e",
        "SANDBOX_MEMORY_LIMIT=512m", // optional
        "-e",
        "SANDBOX_CPU_LIMIT=0.75", // optional
        "mcp/node-code-sandbox"
      ]
    }
  }
}

or with NPX:

{
  "mcpServers": {
    "node-code-sandbox-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "node-code-sandbox-mcp"],
      "env": {
        "FILES_DIR": "/Users/alfonsograziano/Desktop/node-sandbox",
        "SANDBOX_MEMORY_LIMIT": "512m", // optional
        "SANDBOX_CPU_LIMIT": "0.75" // optional
      }
    }
  }
}

> Note: Ensure your working directory points to the built server, and Docker is installed/running.

Docker

Run the server in a container (mount Docker socket if needed), and pass through your desired host output directory as an env var:

# Build locally if necessary
# docker build -t mcp/node-code-sandbox .

docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$HOME/Desktop/sandbox-output":"/root" \
  -e FILES_DIR="$HOME/Desktop/sandbox-output" \
  -e SANDBOX_MEMORY_LIMIT="512m" \
  -e SANDBOX_CPU_LIMIT="0.5" \
  mcp/node-code-sandbox stdio

This bind-mounts your host folder into the container at the **same absolute path** and makes `FILES_DIR` available inside the MCP server.

Ephemeral usage – **no persistent storage**

docker run --rm -it \
  -v /var/run/docker.sock:/var/run/docker.sock \
  alfonsograziano/node-code-sandbox-mcp stdio

Usage with VS Code

**Quick install** buttons (VS Code & Insiders):

Install js-sandbox-mcp (NPX) Install js-sandbox-mcp (Docker)

**Manual configuration**: Add to your VS Code `settings.json` or `.vscode/mcp.json`:

"mcp": {
    "servers": {
        "js-sandbox": {
            "command": "docker",
            "args": [
                "run",
                "-i",
                "--rm",
                "-v", "/var/run/docker.sock:/var/run/docker.sock",
                "-v", "$HOME/Desktop/sandbox-output:/root", // optional
                "-e", "FILES_DIR=$HOME/Desktop/sandbox-output",  // optional
                "-e", "SANDBOX_MEMORY_LIMIT=512m",
                "-e", "SANDBOX_CPU_LIMIT=1",
                "mcp/node-code-sandbox"
              ]
        }
    }
}

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 325 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # 🐢🚀 Node.js Sandbox MCP Server
  2. Node.js server implementing the Model Context Protocol (MCP) for running arbitrary JavaScript in ephemeral Docker containers with on‑the‑fly npm dependency installation.
  3. ![Website Preview](https://raw.githubusercontent.com/alfonsograziano/node-code-sandbox-mcp/master/assets/images/website_homepage.png)
  4. 👉 [Look at the official website](https://jsdevai.com/)
  5. 📦 [Available on Docker Hub](https://hub.docker.com/r/mcp/node-code-sandbox)
  6. ## Features
  7. - Start and manage isolated Node.js sandbox containers
  8. - Execute arbitrary shell commands inside containers
  9. - Install specified npm dependencies per job
  10. - Run ES module JavaScript snippets and capture stdout
  11. - Tear down containers cleanly
  12. - **Detached Mode:** Keep the container alive after script execution (e.g. for long-running servers)
  13. > Note: Containers run with controlled CPU/memory limits.
  14. ## Explore Cool Use Cases
  15. If you want ideas for cool and powerful ways to use this library, check out the [use cases section on the website](https://jsdevai.com/#use-cases)
  16. It contains a curated list of prompts, examples, and creative experiments you can try with the Node.js Sandbox MCP Server.
  17. ## ⚠️ Prerequisites
  18. To use this MCP server, Docker must be installed and running on your machine.
  19. **Tip:** Pre-pull any Docker images you'll need to avoid delays during first execution.
  20. Example recommended images:
  21. - node:lts-slim
  22. - mcr.microsoft.com/playwright:v1.55.0-noble
  23. - alfonsograziano/node-chartjs-canvas:latest
  24. ## Getting started
  25. In order to get started with this MCP server, first of all you need to connect it to a client (for example Claude Desktop).
  26. Once it's running, you can test that it's fully working with a couple of test prompts:
  27. - Validate that the tool can run:
  28. ```markdown
  29. Create and run a JS script with a console.log("Hello World")
  30. ```
  31. This should run a console.log and in the tool response you should be able to see Hello World.
  32. - Validate that you can install dependencies and save files
  33. ```markdown
  34. Create and run a JS script that generates a QR code for the URL `https://nodejs.org/en`, and save it as `qrcode.png` **Tip:** Use the `qrcode` package.
  35. ```
  36. This should create a file in your mounted directory (for example the Desktop) called "qrcode.png"
  37. ### Usage with Claude Desktop
  38. Add this to your `claude_desktop_config.json`:
  39. You can follow the [Official Guide](https://modelcontextprotocol.io/quickstart/user) to install this MCP server
  40. ```json
  41. {
  42. "mcpServers": {
  43. "js-sandbox": {
  44. "command": "docker",
  45. "args": [
  46. "run",
  47. "-i",
  48. "--rm",
  49. "-v",
  50. "/var/run/docker.sock:/var/run/docker.sock",
  51. "-v",
  52. "$HOME/Desktop/sandbox-output:/root",
  53. "-e",
  54. "FILES_DIR=$HOME/Desktop/sandbox-output",
  55. "-e",
  56. "SANDBOX_MEMORY_LIMIT=512m", // optional
  57. "-e",
  58. "SANDBOX_CPU_LIMIT=0.75", // optional
  59. "mcp/node-code-sandbox"
  60. ]
  61. }
  62. }
  63. }
  64. ```
  65. or with NPX:
  66. ```json
  67. {
  68. "mcpServers": {
  69. "node-code-sandbox-mcp": {
  70. "type": "stdio",
  71. "command": "npx",
  72. "args": ["-y", "node-code-sandbox-mcp"],
  73. "env": {
  74. "FILES_DIR": "/Users/alfonsograziano/Desktop/node-sandbox",
  75. "SANDBOX_MEMORY_LIMIT": "512m", // optional
  76. "SANDBOX_CPU_LIMIT": "0.75" // optional
  77. }
  78. }
  79. }
  80. }
  81. ```
  82. > Note: Ensure your working directory points to the built server, and Docker is installed/running.
  83. ### Docker
  84. Run the server in a container (mount Docker socket if needed), and pass through your desired host output directory as an env var:
  85. ```shell
  86. # Build locally if necessary
  87. # docker build -t mcp/node-code-sandbox .
  88. docker run --rm -it \
  89. -v /var/run/docker.sock:/var/run/docker.sock \
  90. -v "$HOME/Desktop/sandbox-output":"/root" \
  91. -e FILES_DIR="$HOME/Desktop/sandbox-output" \
  92. -e SANDBOX_MEMORY_LIMIT="512m" \
  93. -e SANDBOX_CPU_LIMIT="0.5" \
  94. mcp/node-code-sandbox stdio
  95. ```
  96. This bind-mounts your host folder into the container at the **same absolute path** and makes `FILES_DIR` available inside the MCP server.
  97. #### Ephemeral usage – **no persistent storage**
  98. ```bash
  99. docker run --rm -it \
  100. -v /var/run/docker.sock:/var/run/docker.sock \
  101. alfonsograziano/node-code-sandbox-mcp stdio
  102. ```
  103. ### Usage with VS Code
  104. **Quick install** buttons (VS Code & Insiders):
  105. Install js-sandbox-mcp (NPX) Install js-sandbox-mcp (Docker)
  106. **Manual configuration**: Add to your VS Code `settings.json` or `.vscode/mcp.json`:
  107. ```json
  108. "mcp": {
  109. "servers": {
  110. "js-sandbox": {
  111. "command": "docker",
  112. "args": [
  113. "run",
  114. "-i",
  115. "--rm",
  116. "-v", "/var/run/docker.sock:/var/run/docker.sock",
  117. "-v", "$HOME/Desktop/sandbox-output:/root", // optional
  118. "-e", "FILES_DIR=$HOME/Desktop/sandbox-output", // optional
  119. "-e", "SANDBOX_MEMORY_LIMIT=512m",
  120. "-e", "SANDBOX_CPU_LIMIT=1",
  121. "mcp/node-code-sandbox"
  122. ]
  123. }
  124. }
  125. }
  126. ```
  127. ## API
  128. ## Tools
  129. ### run_js_ephemeral
  130. Run a one-off JS script in a brand-new disposable container.
  131. **Inputs:**
  132. - `image` (string, optional): Docker image to use (default: `node:lts-slim`).
  133. - `code` (string, required): JavaScript source to execute.
  134. - `dependencies` (array of `{ name, version }`, optional): NPM packages and versions to install (default: `[]`).
  135. **Behavior:**
  136. 1. Creates a fresh container.
  137. 2. Writes your `index.js` and a minimal `package.json`.
  138. 3. Installs the specified dependencies.
  139. 4. Executes the script.
  140. 5. Tears down (removes) the container.
  141. 6. Returns the captured stdout.
  142. 7. If your code saves any files in the current directory, these files will be returned automatically.
  143. - Images (e.g., PNG, JPEG) are returned as `image` content.
  144. - Other files (e.g., `.txt`, `.json`) are returned as `resource` content.
  145. - Note: the file saving feature is currently available only in the ephemeral tool.
  146. > **Tip:** To get files back, simply save them during your script execution.
  147. **Example Call:**
  148. ```jsonc
  149. {
  150. "name": "run_js_ephemeral",
  151. "arguments": {
  152. "image": "node:lts-slim",
  153. "code": "console.log('One-shot run!');",
  154. "dependencies": [{ "name": "lodash", "version": "^4.17.21" }],
  155. },
  156. }
  157. ```
  158. **Example to save a file:**
  159. ```javascript
  160. import fs from 'fs/promises';
  161. await fs.writeFile('hello.txt', 'Hello world!');
  162. console.log('Saved hello.txt');
  163. ```
  164. This will return the console output **and** the `hello.txt` file.
  165. ### sandbox_initialize
  166. Start a fresh sandbox container.
  167. - **Input**:
  168. - `image` (_string_, optional, default: `node:lts-slim`): Docker image for the sandbox
  169. - `port` (_number_, optional): If set, maps this container port to the host
  170. - **Output**: Container ID string
  171. ### sandbox_exec
  172. Run shell commands inside the running sandbox.
  173. - **Input**:
  174. - `container_id` (_string_): ID from `sandbox_initialize`
  175. - `commands` (_string[]_): Array of shell commands to execute
  176. - **Output**: Combined stdout of each command
  177. ### run_js
  178. Install npm dependencies and execute JavaScript code.
  179. - **Input**:
  180. - `container_id` (_string_): ID from `sandbox_initialize`
  181. - `code` (_string_): JS source to run (ES modules supported)
  182. - `dependencies` (_array of `{ name, version }`_, optional, default: `[]`): npm package names → semver versions
  183. - `listenOnPort` (_number_, optional): If set, leaves the process running and exposes this port to the host (**Detached Mode**)
  184. - **Behavior:**
  185. 1. Creates a temp workspace inside the container
  186. 2. Writes `index.js` and a minimal `package.json`
  187. 3. Runs `npm install --omit=dev --ignore-scripts --no-audit --loglevel=error`
  188. 4. Executes `node index.js` and captures stdout, or leaves process running in background if `listenOnPort` is set
  189. 5. Cleans up workspace unless running in detached mode
  190. - **Output**: Script stdout or background execution notice
  191. ### sandbox_stop
  192. Terminate and remove the sandbox container.
  193. - **Input**:
  194. - `container_id` (_string_): ID from `sandbox_initialize`
  195. - **Output**: Confirmation message
  196. ### search_npm_packages
  197. Search for npm packages by a search term and get their name, description, and a README snippet.
  198. - **Input**:
  199. - `searchTerm` (_string_, required): The term to search for in npm packages. Should contain all relevant context. Use plus signs (+) to combine related terms (e.g., "react+components" for React component libraries).
  200. - `qualifiers` (_object_, optional): Optional qualifiers to filter the search results:
  201. - `author` (_string_, optional): Filter by package author name
  202. - `maintainer` (_string_, optional): Filter by package maintainer name
  203. - `scope` (_string_, optional): Filter by npm scope (e.g., "@vue" for Vue.js packages)
  204. - `keywords` (_string_, optional): Filter by package keywords
  205. - `not` (_string_, optional): Exclude packages matching this criteria (e.g., "insecure")
  206. - `is` (_string_, optional): Include only packages matching this criteria (e.g., "unstable")
  207. - `boostExact` (_string_, optional): Boost exact matches for this term in search results
  208. - **Behavior:**
  209. 1. Searches the npm registry using the provided search term and qualifiers
  210. 2. Returns up to 5 packages sorted by popularity
  211. 3. For each package, provides name, description, and README snippet (first 500 characters)
  212. - **Output**: JSON array containing package details with name, description, and README snippet
  213. ## Usage Tips
  214. - **Session-based tools** (`sandbox_initialize` ➔ `run_js` ➔ `sandbox_stop`) are ideal when you want to:
  215. - Keep a long-lived sandbox container open.
  216. - Run multiple commands or scripts in the same environment.
  217. - Incrementally install and reuse dependencies.
  218. - **One-shot execution** with `run_js_ephemeral` is perfect for:
  219. - Quick experiments or simple scripts.
  220. - Cases where you don't need to maintain state or cache dependencies.
  221. - Clean, atomic runs without worrying about manual teardown.
  222. - **Detached mode** is useful when you want to:
  223. - Spin up servers or long-lived services on-the-fly
  224. - Expose and test endpoints from running containers
  225. Choose the workflow that best fits your use-case!
  226. ## Build
  227. Compile and bundle:
  228. ```shell
  229. npm install
  230. npm run build
  231. ```
  232. ## License
  233. MIT License
  234. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  235. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  236. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  237. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  238. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  239. OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.