Node.js MCP server for secure sandboxed JavaScript execution with Docker containers and on-the-fly dependencies
The Node.js Sandbox MCP Server is designed to facilitate the execution of arbitrary JavaScript in ephemeral Docker containers, providing a sandbox environment for developing and testing scripts on the fly. This server leverages Model Context Protocol (MCP), a standardized interface enabling seamless integration with various AI applications like Claude Desktop, Continue, and Cursor.
The Node.js Sandbox MCP Server offers robust features that enhance its utility in AI workflows:
The Node.js Sandbox MCP Server implements Model Context Protocol (MCP) to ensure compatibility with various AI applications. The protocol itself is designed to standardize interactions between clients and servers, fostering a user-friendly experience across different platforms and tools.
sandbox_initialize API call to launch a sandbox container.sandbox_exec API for running shell commands in the active sandbox context.run_js_ephemeral and run_js APIs allow you to run JS snippets or full scripts with the option of pre-install npm dependencies.sandbox_stop API to ensure resources are freed up.graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
graph TD;
subgraph AI Application
A[Client] -->|Request| B[MCP Client]
end
subgraph MCP Protocol
B --> C[Node.js Sandbox Server]
C --> D[Container Management]
D --> E[Data Source/Tool]
F[Captured Output]
end
To get started, follow these steps:
Clone the Repository: Obtain the Node.js Sandbox MCP server code from GitHub.
git clone https://github.com/user/node-sandbox-mcp.git
Navigate to the Code Directory:
cd node-sandbox-mcp
Install Dependencies: Ensure npm is installed and then run the following command:
npm install
Build the Server:
npm run build
Run the MCP Server: You can choose to run it in a Docker container if needed.
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
alfonsograziano/node-code-sandbox-mcp stdio
Developers can create a set of test cases for a new library or module. Each test is run within an isolated sandbox, ensuring consistency and preventing interference between different tests.
// Example Test Script
const fs = require('fs/promises');
await fs.writeFile("test-result.txt", "Test completed successfully!");
console.log("Saved test-result.txt");
Perform real-time data analysis on datasets where the necessary tools and libraries might change frequently. The server allows for easy installation and removal of dependencies as needed.
The Node.js Sandbox MCP Server supports integration with popular AI applications:
graph TD;
subgraph "MCP Client Compatibility"
A[Claude Desktop] -->|Supports| B[AI Application Integration]
C[Continue] -->|Full Support| D[Data Source/Tool Access]
E[Cursor] -->|Tools Only| F[Prompt Processing Limitations]
end
The server has been tested for compatibility with several platforms and tools:
Configure environmental variables as needed for the server instance:
{
"mcpServers": {
"js-sandbox": {
"command": "node",
"args": ["dist/server.js", "stdio"],
"cwd": "/path/to/js-sandbox-mcp",
"env": {
"API_KEY": "your-api-key"
}
}
}
}
sandbox_initialize method starts a persistent sandbox that can be re-used for running multiple commands or scripts across sessions.dependencies argument in the run_js_ephemeral and run_js APIs to specify which npm packages are required by each script.{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
By harnessing the power of Node.js Sandbox MCP Server, you can significantly enhance your AI application's capabilities, providing a robust and flexible environment for dynamic script execution and tool integration.
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration