Cover image
Try Now
2025-04-14

Python sandboxes for llms

3 years

Works with Finder

4

Github Watches

0

Github Forks

4

Github Stars

MCP Sandbox

MCP Sandbox Logo

Feel free to try on mcp sandbox

Python Version License UV MCP

中文文档 | English

Early stage, subject to changes

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.

Features

  • 🐳 Docker Isolation: Securely run Python code in isolated Docker containers
  • 📦 Package Management: Easily install and manage Python packages
  • 📊 File Generation: Support for generating files and accessing them via web links

Installation

# 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.

Available Tools

  1. create_sandbox: Creates a new Python Docker sandbox and returns its ID for subsequent code execution and package installation
  2. list_sandboxes: Lists all existing sandboxes (Docker containers) for reuse
  3. execute_python_code: Executes Python code in a specified Docker sandbox
  4. install_package_in_sandbox: Installs Python packages in a specified Docker sandbox
  5. check_package_installation_status: Checks if a package is installed or installation status in a Docker sandbox
  6. execute_terminal_command: Executes a terminal command in the specified Docker sandbox. Parameters: sandbox_id (string), command (string). Returns stdout, stderr, exit_code.
  7. upload_file_to_sandbox: Uploads a local file to the specified Docker sandbox. Parameters: sandbox_id (string), local_file_path (string), dest_path (string, optional, default: /app/results).

Project Structure

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

Example Prompt

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.

MCP Example Config

Below is an example config for claude:

{
  "mcpServers": {
    "mcpSandbox": {
      "command": "npx",
      "args": ["-y", "supergateway", "--sse",  "http://localhost:8000/sse"]
    }
  }
}

MCP Example Config for Online Demo

{
  "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.

相关推荐

  • 1Panel-dev
  • 🔥 1Panel provides an intuitive web interface and MCP Server to manage websites, files, containers, databases, and LLMs on a Linux server.

  • av
  • Effortlessly run LLM backends, APIs, frontends, and services with one command.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的LLM资料总结(数据处理、模型训练、模型部署、o1 模型、MCP、小语言模型、视觉语言模型) | Summary of the world's best LLM resources.

  • sigoden
  • Easily create LLM tools and agents using plain Bash/JavaScript/Python functions.

  • hkr04
  • Lightweight C++ MCP (Model Context Protocol) SDK

  • RockChinQ
  • 😎简单易用、🧩丰富生态 - 大模型原生即时通信机器人平台 | 适配 QQ / 微信(企业微信、个人微信)/ 飞书 / 钉钉 / Discord / Telegram / Slack 等平台 | 支持 ChatGPT、DeepSeek、Dify、Claude、Gemini、xAI、PPIO、Ollama、LM Studio、阿里云百炼、火山方舟、SiliconFlow、Qwen、Moonshot、ChatGLM、SillyTraven、MCP 等 LLM 的机器人 / Agent | LLM-based instant messaging bots platform, supports Discord, Telegram, WeChat, Lark, DingTalk, QQ, Slack

  • paulwing
  • A test repository created using MCP service

  • dmayboroda
  • On-premises conversational RAG with configurable containers

  • tawago
  • Artifact2MCP Generator allows generation of MCP server automatically & dynamically given smart contract's compiled artifact (chain‑agnostic)

    Reviews

    3.1 (13)
    Avatar
    user_I1bFWKoP
    2025-04-24

    As a dedicated mcp-sandbox user, I am thoroughly impressed by the seamless experience it offers. Developed by JohanLi233, this application provides an excellent environment for experimentation and learning. The intuitive interface and robust features ensure even beginners can dive right into sandboxing projects easily. Highly recommend for anyone looking to explore and test in a safe space!

    Avatar
    user_ysGMDUWG
    2025-04-24

    I've been using mcp-sandbox by JohanLi233, and it has exceeded my expectations! It's incredibly intuitive and perfect for experimenting with new ideas. The initial setup is smooth, and the welcome message makes you feel right at home. Highly recommend it to anyone looking for a reliable and user-friendly sandbox environment.

    Avatar
    user_osqDzeLN
    2025-04-24

    I have been using the mcp-sandbox for a while now and it has been an outstanding experience. Created by JohanLi233, this tool is extremely user-friendly and reliable. It has greatly simplified my workflow and I highly recommend it to anyone in need of a solid sandbox environment. The welcome information is clear and the start URL makes it easy to dive right in. Kudos to the developer for such a great product!

    Avatar
    user_nNQoKM4i
    2025-04-24

    As a dedicated user of the mcp-sandbox developed by JohanLi233, I have found it to be an invaluable tool. The seamless integration and user-friendly interface make it ideal for both beginners and experienced professionals. It's clear that a lot of thought went into its development, and I highly recommend giving it a try!

    Avatar
    user_Gnf6mbFj
    2025-04-24

    As a devoted user of mcp applications, I must say that mcp-sandbox created by JohanLi233 is a brilliant tool. It seamlessly integrates with my projects, providing a smooth and efficient experience. The sandbox environment is intuitive, making it easy to test and innovate without hassle. Highly recommend it to developers looking for a reliable and user-friendly solution!

    Avatar
    user_tOtyGjvL
    2025-04-24

    The mcp-sandbox by JohanLi233 is an incredibly powerful and user-friendly tool for anyone diving into sandbox environments. Its intuitive interface and seamless integration have significantly boosted my productivity. Highly recommend it to developers and enthusiasts alike!

    Avatar
    user_iynXocvy
    2025-04-24

    As a dedicated user of mcp-sandbox by JohanLi233, I can confidently say that this tool has significantly enhanced my development workflow. The intuitive interface and extensive features make sandboxing projects seamless and efficient. Highly recommended for anyone looking to streamline their coding environment!

    Avatar
    user_ElzRREX6
    2025-04-24

    As a dedicated user of mcp-sandbox created by JohanLi233, I am thoroughly impressed with its capabilities. The tool offers a seamless and robust environment for testing and experimentation, making it indispensable for developers. The intuitive interface and comprehensive features significantly enhance productivity. Highly recommend!

    Avatar
    user_alCMNgHP
    2025-04-24

    mcp-sandbox by JohanLi233 is an incredibly versatile tool for developers looking to experiment in a controlled environment. Its user-friendly interface and robust features allow for efficient testing and development. Highly recommended for anyone in need of a reliable sandbox solution!

    Avatar
    user_TsDOWO5s
    2025-04-24

    As a dedicated user of mcp-sandbox by JohanLi233, I am thoroughly impressed with its capabilities. The tool is incredibly user-friendly, making it simple for anyone to navigate and execute tasks efficiently. The welcome information is precise and helpful, setting the right tone for a productive experience. I highly recommend this for anyone looking to enhance their development process.

    Avatar
    user_theYendH
    2025-04-24

    The mcp-sandbox by JohanLi233 is an innovative and user-friendly tool that has truly impressed me. It is versatile and easy to navigate, making it a perfect choice for both beginners and advanced users. The interface is clean and well-designed, ensuring a smooth experience. Highly recommend giving it a try!

    Avatar
    user_PQ2DnXyb
    2025-04-24

    As a dedicated user of the mcp-sandbox by JohanLi233, I absolutely love how seamless and efficient the platform is. It provides a robust environment for testing and development, perfect for experimenting without any risk. The user-friendly interface and comprehensive features make it an indispensable tool for any developer. Highly recommend giving it a try!

    Avatar
    user_R2j3XmDs
    2025-04-24

    I've been using mcp-sandbox by JohanLi233 and it's a fantastic tool! The interface is user-friendly and it provides a great environment for testing and development. Highly recommend it for anyone looking for a reliable sandbox.