The Code Sandbox MCP Server provides a secure environment for AI assistants and LLM applications to execute code snippets using containerized environments. It leverages the llm-sandbox package to safely run code in isolated containers, capturing and returning the execution results.
You can install the Code Sandbox MCP Server directly from GitHub using pip:
pip install git+https://github.com/philschmid/code-sandbox-mcp.git
To use the Code Sandbox MCP Server, you need to add it to your Model Context Protocol (MCP) client's configuration. The server is designed to be launched on-demand by the client.
Add the following to your mcpServers
configuration:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp",
}
}
}
The Code Sandbox MCP Server provides the following tools:
Executes Python code in a secure, isolated sandbox:
# Example Python code execution
def hello():
return "Hello, world!"
print(hello())
Executes JavaScript (Node.js) code in a secure, isolated sandbox:
// Example JavaScript code execution
function hello() {
return "Hello, world!";
}
console.log(hello());
The server comes with two pre-built container images:
philschmi/code-sandbox-python:latest
philschmi/code-sandbox-js:latest
You can build custom images with:
docker build -t philschmi/code-sandbox-python:latest -f containers/Dockerfile.python .
docker build -t philschmi/code-sandbox-js:latest -f containers/Dockerfile.nodejs .
To use your custom images, you can either:
Pass flags when starting the MCP server:
code-sandbox-mcp --python-image your-image-name --js-image your-js-image
Update the image names in the source code constants file
To push custom images to Docker Hub:
docker tag philschmi/code-sandbox-python:latest <your-account>/code-sandbox-python:latest
docker push <your-account>/code-sandbox-python:latest
You can test your server using the MCP inspector:
npx @modelcontextprotocol/inspector
This allows you to inspect and debug the server's behavior when processing code execution requests.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "code-sandbox" '{"command":"code-sandbox-mcp"}'
See the official Claude Code MCP documentation for more details.
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 > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp"
}
}
}
3. Restart Claude Desktop for the changes to take effect