The Code Sandbox MCP Server is a secure Docker-based solution for executing code in multiple languages that implements the Model Context Protocol. It runs in isolated containers with resource limits and supports 12 programming languages including Python, JavaScript, Ruby, and various JVM languages.
# Pull the latest image from GitHub Container Registry
docker pull ghcr.io/timlikesai/code-sandbox-mcp:latest
# Run directly
docker run --rm --interactive ghcr.io/timlikesai/code-sandbox-mcp:latest
# Build the Docker image
docker compose build
# Run tests (optional)
docker compose run --rm code-sandbox bundle exec rspec
Add this configuration to Claude Desktop settings file or Claude Code's .mcp.json
file:
{
"mcpServers": {
"code-sandbox": {
"command": "docker",
"args": [
"run", "--rm", "--interactive",
"--network", "none",
"ghcr.io/timlikesai/code-sandbox-mcp:latest"
]
}
}
}
For Claude Code CLI, you can add via command line:
claude mcp add code-sandbox -- docker run --rm --interactive --network none ghcr.io/timlikesai/code-sandbox-mcp:latest
For additional security hardening:
{
"mcpServers": {
"code-sandbox": {
"command": "docker",
"args": [
"run", "--rm", "--interactive",
"--read-only",
"--tmpfs", "/tmp",
"--tmpfs", "/app/tmp",
"--memory", "512m",
"--cpus", "0.5",
"--network", "none",
"--security-opt", "no-new-privileges",
"--cap-drop", "ALL",
"ghcr.io/timlikesai/code-sandbox-mcp:latest"
]
}
}
}
The container supports networking, but it's recommended to use Docker's --network none
flag to disable it for security. To enable network access when needed, remove this flag:
{
"mcpServers": {
"code-sandbox": {
"command": "docker",
"args": [
"run", "--rm", "--interactive",
"--network", "none",
"ghcr.io/timlikesai/code-sandbox-mcp:latest"
]
},
"code-sandbox-network": {
"command": "docker",
"args": [
"run", "--rm", "--interactive",
"ghcr.io/timlikesai/code-sandbox-mcp:latest"
]
}
}
}
Network access is required for API calls, package installation, web scraping, and external service integration.
The MCP server provides three main tools:
Code execution is stateful by default. Each language maintains its own isolated session with variables, function/class definitions, imported modules, and execution history. Sessions expire after 1 hour of inactivity.
# Test execution (with network disabled)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"execute_code","arguments":{"language":"python","code":"print(\"Hello World!\")"}}}' | docker run --rm -i --network none ghcr.io/timlikesai/code-sandbox-mcp:latest
# Test with network access and package installation
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"execute_code","arguments":{"language":"python","code":"import subprocess; subprocess.run([\"pip\", \"install\", \"requests\"]); import requests; print(requests.get(\"https://httpbin.org/ip\").json())"}}}' | docker run --rm -i ghcr.io/timlikesai/code-sandbox-mcp:latest
# Debug mode
docker run --rm -it --network none ghcr.io/timlikesai/code-sandbox-mcp:latest bash
The server implements multiple layers of container security:
--network none
flag)/tmp
only--security-opt no-new-privileges
, --cap-drop ALL
)sandbox
user)--rm
removes containers after execution)EXECUTION_TIMEOUT
)When network access is enabled, users can install packages safely within the container. All installations are ephemeral and don't affect the host system or persist between container restarts.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "code-sandbox" '{"command":"docker","args":["run","--rm","--interactive","--network","none","ghcr.io/timlikesai/code-sandbox-mcp:latest"]}'
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": "docker",
"args": [
"run",
"--rm",
"--interactive",
"--network",
"none",
"ghcr.io/timlikesai/code-sandbox-mcp:latest"
]
}
}
}
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": "docker",
"args": [
"run",
"--rm",
"--interactive",
"--network",
"none",
"ghcr.io/timlikesai/code-sandbox-mcp:latest"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect