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.
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
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"
]
}
}
}
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.
The server provides several tools for JavaScript execution:
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.
For more complex scenarios where you need to maintain state:
{
"name": "sandbox_initialize",
"arguments": {
"image": "node:20-slim"
}
}
{
"name": "sandbox_exec",
"arguments": {
"container_id": "your_container_id",
"commands": ["ls -la", "node --version"]
}
}
{
"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" }]
}
}
{
"name": "sandbox_stop",
"arguments": {
"container_id": "your_container_id"
}
}
Session-based tools are best for:
One-shot execution with run_js_ephemeral
is ideal for:
Choose the workflow that best fits your specific needs.
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.
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"
]
}
}
}
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.
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.