This MCP Code Sandbox Server provides secure code execution capabilities in isolated sandbox environments, following the Message Communication Protocol (MCP) standard. It's compatible with Claude for Desktop and other MCP clients, allowing you to execute Python code, manage files, and install packages in a secure environment.
Clone the repository:
git clone https://github.com/yourusername/mcp-code-sandbox.git
cd mcp-code-sandbox
Set up a virtual environment:
# Using venv
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Or using uv (recommended)
uv init
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Install required packages:
# Using pip
pip install fastmcp python-dotenv e2b-code-interpreter
# Or using uv
uv add fastmcp python-dotenv e2b-code-interpreter
Configure environment variables by creating a .env
file:
E2B_API_KEY=your_e2b_api_key_here
INTERPRETER_TYPE=e2b # Default, can be changed to other implemented interpreters
Start the server directly from the command line:
python main.py
This launches the server using stdio transport, making it compatible with Claude for Desktop.
Ensure you have the latest version of Claude for Desktop
Open your Claude for Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Add your code sandbox server configuration:
{
"mcpServers": {
"code-sandbox": {
"command": "python",
"args": [
"/ABSOLUTE/PATH/TO/main.py"
]
}
}
}
Or if using uv
:
{
"mcpServers": {
"code-sandbox": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PROJECT_DIRECTORY",
"run",
"main.py"
]
}
}
}
Save the file and restart Claude for Desktop
If you encounter issues:
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.