The Code Sandbox MCP Server is a lightweight tool that allows AI assistants and LLM applications to safely execute code snippets in containerized environments. It provides a secure way to run Python and JavaScript code through the Model Context Protocol (MCP).
You can install the Code Sandbox MCP Server using pip:
pip install git+https://github.com/philschmid/code-sandbox-mcp.git
The server provides two main tools:
To use the Code Sandbox MCP server, add it to your MCP client's configuration file:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp"
}
}
}
You can securely pass environment variables to the sandbox:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp",
"args": ["--pass-through-env", "API_KEY,SECRET_TOKEN"],
"env": {
"API_KEY": "1234567890",
"SECRET_TOKEN": "1234567890"
}
}
}
}
You can specify a custom container image:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp",
"env": {
"CONTAINER_IMAGE": "your-own-image",
"CONTAINER_LANGUAGE": "python"
}
}
}
}
Here's how to use the server with the Gemini SDK:
from fastmcp import Client
from google import genai
import asyncio
mcp_client = Client(
{
"local_server": {
"transport": "stdio",
"command": "code-sandbox-mcp",
}
}
)
gemini_client = genai.Client()
async def main():
async with mcp_client:
response = await gemini_client.aio.models.generate_content(
model="gemini-2.5-flash",
contents="Use Python to ping the google.com website and return the response time.",
config=genai.types.GenerateContentConfig(
temperature=0,
tools=[mcp_client.session], # Pass the FastMCP client session
),
)
print(response.text)
if __name__ == "__main__":
asyncio.run(main())
Add the MCP server configuration to your Gemini CLI settings:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp"
}
}
}
You can add this either to your global settings at ~/.gemini/settings.json or to your project's .gemini/settings.json file.
You can test your server using the MCP inspector:
npx @modelcontextprotocol/inspector
To run the test suite:
# Install development dependencies
pip install -e ".[dev]"
# Run the tests
pytest tests/
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.json2. Add this to your configuration file:
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp"
}
}
}
3. Restart Claude Desktop for the changes to take effect