Node Code Sandbox MCP server

Provides a secure Docker-based sandbox for executing JavaScript code with npm dependencies, offering both persistent and ephemeral containers with strict resource limits for safe code testing and demonstration.
Back to servers
Provider
Alfonso Graziano
Release date
Apr 26, 2025
Language
TypeScript
Stats
15 stars

The Node.js Sandbox MCP Server implements the Model Context Protocol (MCP) for executing JavaScript code within isolated Docker containers. It allows for secure code execution with on-demand npm dependency installation while maintaining full container isolation for safety and resource management.

Features

  • Isolated Node.js sandbox containers with controlled CPU/memory limits
  • Execution of arbitrary shell commands inside containers
  • On-the-fly npm dependency installation
  • ES module JavaScript support with stdout capture
  • Clean container teardown after use

Installation

Docker Installation (Recommended)

The easiest way to use the server is via Docker:

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

Integration with Claude Desktop

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "js-sandbox": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "/var/run/docker.sock:/var/run/docker.sock",
        "alfonsograziano/node-code-sandbox-mcp"
      ]
    }
  }
}

Integration with VS Code

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",
                "alfonsograziano/node-code-sandbox-mcp"
              ],
        }
    }
}

You can also follow the Official MCP Guide for detailed installation instructions.

Usage

The server provides several tools for JavaScript execution:

One-Shot Execution with run_js_ephemeral

Perfect for quick, isolated script execution:

{
  "name": "run_js_ephemeral",
  "arguments": {
    "image": "node:20-slim",
    "code": "console.log('Hello, world!');",
    "dependencies": [{ "name": "lodash", "version": "^4.17.21" }]
  }
}

This creates a fresh container, installs dependencies, runs the code, and automatically removes the container afterward.

Session-Based Workflow

For more complex scenarios where you need to maintain state:

  1. Initialize a sandbox:
{
  "name": "sandbox_initialize",
  "arguments": {
    "image": "node:20-slim"
  }
}
  1. Execute shell commands in the container:
{
  "name": "sandbox_exec",
  "arguments": {
    "container_id": "your_container_id",
    "commands": ["ls -la", "node --version"]
  }
}
  1. Run JavaScript with dependencies:
{
  "name": "run_js",
  "arguments": {
    "container_id": "your_container_id",
    "code": "import _ from 'lodash'; console.log(_.camelCase('Hello World'));",
    "dependencies": [{ "name": "lodash", "version": "^4.17.21" }]
  }
}
  1. Clean up when finished:
{
  "name": "sandbox_stop",
  "arguments": {
    "container_id": "your_container_id"
  }
}

Usage Tips

  • Session-based tools are best for:

    • Maintaining a persistent environment
    • Running multiple commands in sequence
    • Reusing installed dependencies
  • One-shot execution with run_js_ephemeral is ideal for:

    • Simple, quick scripts
    • Isolated runs with no state maintenance
    • Clean execution without manual cleanup

Choose the workflow that best fits your specific needs.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later