Python MCP Sandbox

Integrations

  • Runs Python code in isolated Docker containers for secure execution, enabling safe installation of packages and execution of arbitrary Python code

  • Supports installation and usage of NumPy library in the Python environment as mentioned in the example workflow

  • Supports installation and usage of pandas library for data analysis as mentioned in the example workflow

Sandbox de MCP

Siéntete libre de probarlo en mcp sandbox

Chino tradicional | Inglés

Manifestación

Python MCP Sandbox es una herramienta interactiva de ejecución de código Python que permite a los usuarios y LLM ejecutar de forma segura código Python e instalar paquetes en contenedores Docker aislados.

Características

  • 🐳 Aislamiento de Docker : ejecute de forma segura código Python en contenedores Docker aislados
  • 📦 Gestión de paquetes : instala y administra fácilmente paquetes de Python
  • 📊 Generación de archivos : Soporte para generar archivos y acceder a ellos a través de enlaces web

Instalación

# 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

El punto final SSE predeterminado es http://localhost:8000/sse y puede interactuar con él a través del Inspector MCP mediante SSE o cualquier otro cliente que admita conexiones SSE.

Herramientas disponibles

  1. create_sandbox : crea un nuevo entorno aislado de Python Docker y devuelve su ID para la posterior ejecución del código y la instalación del paquete.
  2. list_sandboxes : enumera todos los entornos sandbox existentes (contenedores Docker) para su reutilización
  3. execute_python_code : ejecuta código Python en un entorno sandbox de Docker especificado
  4. install_package_in_sandbox : instala paquetes de Python en un entorno aislado de Docker especificado
  5. check_package_installation_status : Comprueba si un paquete está instalado o el estado de instalación en un entorno sandbox de Docker
  6. execute_terminal_command : Ejecuta un comando de terminal en el entorno de pruebas de Docker especificado. Parámetros: sandbox_id (cadena), command (cadena). Devuelve stdout , stderr y exit_code .
  7. upload_file_to_sandbox : Sube un archivo local al entorno de pruebas de Docker especificado. Parámetros: sandbox_id (cadena), local_file_path (cadena), dest_path (cadena, opcional, valor predeterminado: /app/results ).

Estructura del proyecto

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

Ejemplo de mensaje

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.

Ejemplo de configuración de MCP

A continuación se muestra un ejemplo de configuración para Claude:

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

Ejemplo de configuración de MCP para demostración en línea

{ "mcpServers": { "mcpSandbox": { "command": "npx", "args": ["-y", "supergateway", "--sse", "http://115.190.87.78/sse?api_key=<API_KEY>"] } } }

Modifique el serverUrl según sea necesario para su entorno.

-
security - not tested
A
license - permissive license
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

Un entorno interactivo de ejecución de código Python que permite a los usuarios y LLM ejecutar de forma segura código Python e instalar paquetes en contenedores Docker aislados.

  1. Feel free to try on mcp sandbox
    1. Demo
      1. Features
      2. Installation
      3. Project Structure
      4. Example Prompt
      5. MCP Example Config
      6. MCP Example Config for Online Demo

    Related MCP Servers

    • -
      security
      F
      license
      -
      quality
      Provides isolated Docker environments for code execution, enabling users to create and manage containers, execute multi-language code, save and reproduce development environments, ensuring security and isolation.
      Last updated -
      6
      Python
      • Apple
    • A
      security
      A
      license
      A
      quality
      Allows LLMs to execute Python code in a specified Conda environment, enabling access to necessary libraries and dependencies for efficient code execution.
      Last updated -
      1
      29
      JavaScript
      MIT License
    • -
      security
      A
      license
      -
      quality
      Facilitates isolated code execution within Docker containers, enabling secure multi-language script execution and integration with language models like Claude via the Model Context Protocol.
      Last updated -
      Python
      MIT License
      • Linux
      • Apple
    • A
      security
      A
      license
      A
      quality
      A server that provides a persistent Python REPL environment through the MCP protocol, allowing execution of Python code, variable management, and package installation.
      Last updated -
      3
      3
      Python
      MIT License

    View all related MCP servers

    ID: 337zco6046