An interactive sandbox to safely execute Python code and install packages in isolated Docker containers.
中文文档 | English
Python MCP Sandbox is an interactive Python code execution tool that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.
Viby works with mcp sandbox
# Clone the repository
git clone https://github.com/JohanLi233/python-mcp-sandbox.git
cd python-mcp-sandbox
uv venv
uv sync
# Start the server
uv run main.py
The default SSE endpoint is http://localhost:8000/sse, and you can interact with it via the MCP Inspector through SSE or any other client that supports SSE connections.
sandbox_id
(string), command
(string). Returns stdout
, stderr
, exit_code
.sandbox_id
(string), local_file_path
(string), dest_path
(string, optional, default: /app/results
).python-mcp-sandbox/
├── main.py # Application entry point
├── requirements.txt # Project dependencies
├── Dockerfile # Docker configuration for Python containers
├── results/ # Directory for generated files
├── mcp_sandbox/ # Main package directory
│ ├── __init__.py
│ ├── models.py # Pydantic models
│ ├── api/ # API related components
│ │ ├── __init__.py
│ │ └── routes.py # API route definitions
│ ├── core/ # Core functionality
│ │ ├── __init__.py
│ │ ├── docker_manager.py # Docker container management
│ │ └── mcp_tools.py # MCP tools
│ └── utils/ # Utilities
│ ├── __init__.py
│ ├── config.py # Configuration constants
│ ├── file_manager.py # File management
│ └── task_manager.py # Periodic task management
└── README.md # Project documentation
I've configured a Python code execution sandbox for you. You can run Python code using the following steps:
1. First, use the "list_sandboxes" tool to view all existing sandboxes (Docker containers).
- You can reuse an existing sandbox_id if a sandbox exists, do not create a new one.
- If you need a new sandbox, use the "create_sandbox" tool.
- Each sandbox is an isolated Python environment, and the sandbox_id is required for all subsequent operations.
2. If you need to install packages, use the "install_package_in_sandbox" tool
- Parameters: sandbox_id and package_name (e.g., numpy, pandas)
- This starts asynchronous installation and returns immediately with status
3. After installing packages, you can check their installation status using the "check_package_installation_status" tool
- Parameters: sandbox_id and package_name (name of the package to check)
- If the package is still installing, you need to check again using this tool
4. Use the "execute_python_code" tool to run your code
- Parameters: sandbox_id and code (Python code)
- Returns output, errors and links to any generated files
- All generated files are stored inside the sandbox, and file_links are direct HTTP links for inline viewing
Example workflow:
- Use list_sandboxes to check for available sandboxes, if no available sandboxes, use create_sandbox to create a new one → Get sandbox_id
- Use install_package_in_sandbox to install necessary packages (like pandas, matplotlib), with the sandbox_id parameter
- Use check_package_installation_status to verify package installation, with the same sandbox_id parameter
- Use execute_python_code to run your code, with the sandbox_id parameter
Code execution happens in a secure sandbox. Generated files (images, CSVs, etc.) will be provided as direct HTTP links, which can viewed inline in the browser.
Remember not to use plt.show() in your Python code. For visualizations:
- Save figures to files using plt.savefig() instead of plt.show()
- For data, use methods like df.to_csv() or df.to_excel() to save as files
- All saved files will automatically appear as HTTP links in the results, which you can open or embed directly.
Below is an example config for claude:
{
"mcpServers": {
"mcpSandbox": {
"command": "npx",
"args": ["-y", "supergateway", "--sse", "http://localhost:8000/sse"]
}
}
}
{
"mcpServers": {
"mcpSandbox": {
"command": "npx",
"args": ["-y", "supergateway", "--sse", "http://115.190.87.78/sse?api_key=<API_KEY>"]
}
}
}
Modify the serverUrl
as needed for your environment.
A template for deploying a remote MCP server on Cloudflare Workers, customizable by defining tools in the source code.
A tool server for integrating Dify Workflows via the Model Context Protocol (MCP).
A Python server providing Retrieval-Augmented Generation (RAG) functionality. It indexes various document formats and requires a PostgreSQL database with pgvector.
Convert Figma designs into React Native components.
A knowledge management tool for code repositories using vector embeddings, powered by a local Ollama service.
Interact with your MLOps and LLMOps pipelines through your ZenML MCP server
Parses HAR (HTTP Archive) files and displays requests in a simplified format for AI assistants.
A Python REPL with persistent sessions and automatic dependency management using uv.
Tools for Xcode project management, building, testing, archiving, code signing, and iOS development utilities.
A comprehensive MCP server for managing OPNsense firewalls, offering over 300 tools for configuration and monitoring.