Python MCP Sandbox

by JohanLi233
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

MCP-Sandbox

Probieren Sie es gerne in der MCP-Sandbox aus

中文文档| Englisch

Demo

Python MCP Sandbox ist ein interaktives Tool zur Ausführung von Python-Code, mit dem Benutzer und LLMs Python-Code sicher ausführen und Pakete in isolierten Docker-Containern installieren können.

Viby

Viby funktioniert mit MCP-Sandbox

Merkmale

  • 🐳 Docker-Isolation : Führen Sie Python-Code sicher in isolierten Docker-Containern aus
  • 📦 Paketverwaltung : Einfache Installation und Verwaltung von Python-Paketen
  • 📊 Dateigenerierung : Unterstützung für die Generierung von Dateien und den Zugriff darauf über Weblinks

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

Der Standard-SSE-Endpunkt ist http://localhost:8000/sse und Sie können über den MCP Inspector über SSE oder jeden anderen Client, der SSE-Verbindungen unterstützt, damit interagieren.

Verfügbare Tools

  1. create_sandbox : Erstellt eine neue Python Docker-Sandbox und gibt ihre ID für die nachfolgende Codeausführung und Paketinstallation zurück
  2. list_sandboxes : Listet alle vorhandenen Sandboxen (Docker-Container) zur Wiederverwendung auf
  3. execute_python_code : Führt Python-Code in einer angegebenen Docker-Sandbox aus
  4. install_package_in_sandbox : Installiert Python-Pakete in einer angegebenen Docker-Sandbox
  5. check_package_installation_status : Überprüft, ob ein Paket installiert ist oder den Installationsstatus in einer Docker-Sandbox
  6. execute_terminal_command : Führt einen Terminalbefehl in der angegebenen Docker-Sandbox aus. Parameter: sandbox_id (Zeichenfolge), command (Zeichenfolge). Gibt stdout , stderr und exit_code zurück.
  7. upload_file_to_sandbox : Lädt eine lokale Datei in die angegebene Docker-Sandbox hoch. Parameter: sandbox_id (Zeichenfolge), local_file_path (Zeichenfolge), dest_path (Zeichenfolge, optional, Standard: /app/results ).

Projektstruktur

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

Beispiel-Eingabeaufforderung

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-Beispielkonfiguration

Unten ist eine Beispielkonfiguration für Claude:

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

MCP-Beispielkonfiguration für Online-Demo

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

Ändern Sie die serverUrl nach Bedarf für Ihre Umgebung.

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

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Eine interaktive Python-Codeausführungsumgebung, die es Benutzern und LLMs ermöglicht, Python-Code sicher auszuführen und Pakete in isolierten Docker-Containern zu installieren.

  1. Probieren Sie es gerne in der MCP-Sandbox aus
    1. Demo
      1. Viby
        1. Merkmale
        2. Installation
        3. Projektstruktur
        4. Beispiel-Eingabeaufforderung
        5. MCP-Beispielkonfiguration
        6. MCP-Beispielkonfiguration für 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
        74
        JavaScript
        MIT License
        • Linux
        • Apple
      • -
        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

      MCP directory API

      We provide all the information about MCP servers via our MCP API.

      curl -X GET 'https://glama.ai/api/mcp/v1/servers/JohanLi233/python-mcp-sandbox'

      If you have feedback or need assistance with the MCP directory API, please join our Discord server