PC

philschmid/code-sandbox-mcp

Developer tools

Эта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал

205 stars 21 forks Качество 65 Тренд 17MIT

philschmid/code-sandbox-mcp — это кандидат на MCP-сервер, импортированный из https://github.com/philschmid/code-sandbox-mcp.

Обзор

philschmid/code-sandbox-mcp — это кандидат на MCP-сервер, импортированный из https://github.com/philschmid/code-sandbox-mcp.

Обзор (машинный перевод)

Code Sandbox MCP Server — это лёгкий сервер на основе STDIO Model Context Protocol (MCP), позволяющий ассистентам ИИ и LLM-приложениям безопасно выполнять фрагменты кода в контейнеризированных средах. Он использует пакет llm-sandbox для выполнения фрагментов кода.

Как это работает:

  1. Запускает контейнерную сессию (podman, docker и т.д.) и следит за открытостью сессии.
  2. Записывает code в временный файл на хосте.
  3. Копирует этот временный файл в контейнер в настроенном workdir.
  4. Выполняет команды, специфичные для языка, для запуска кода, например, python python3 -u code.py или javascript node -u code.js
  5. Фиксирует выходные и ошибочные потоки из контейнера.
  6. Возвращает потоки вывода и ошибок клиенту.
  7. Останавливает и снимает контейнер.

Доступные инструменты:

  • run_python_code - Выполняет фрагмент кода на Python в защищённой, изолированной песочнице.
  • code (требуется строка): Код на Python для выполнения.
  • run_js_code — выполняет фрагмент кода JavaScript (Node.js) в защищённой, изолированной песочнице.
  • code (строка, требуется): JavaScript-код для выполнения.

Установка

Начало: использование с MCP-клиентом

Примеры:

Эта страница переведена автоматически. Технические детали смотрите в оригинале.

README

Показан фрагмент оригинального README. Открыть оригинал.

Code Sandbox MCP Server

The Code Sandbox MCP Server is a lightweight, STDIO-based Model Context Protocol (MCP) Server, allowing AI assistants and LLM applications to safely execute code snippets using containerized environments. It is uses the llm-sandbox package to execute the code snippets.

How It Works:

  1. Starts a container session (podman, docker, etc.) and ensures the session is open.
  2. Writes the code to a temporary file on the host.
  3. Copies this temporary file into the container at the configured workdir.
  4. Executes the language-specific commands to run the code, e.g. python python3 -u code.py or javascript node -u code.js
  5. Captures the output and error streams from the container.
  6. Returns the output and error streams to the client.
  7. Stops and removes the container.

Available Tools:

  • run_python_code - Executes a snippet of Python code in a secure, isolated sandbox.
    • code (string, required): The Python code to execute.
  • run_js_code - Executes a snippet of JavaScript (Node.js) code in a secure, isolated sandbox.
    • code (string, required): The JavaScript code to execute.

Installation

pip install git+https://github.com/philschmid/code-sandbox-mcp.git

Getting Started: Usage with an MCP Client

Examples:

To use the Code Sandbox MCP server, you need to add it to your MCP client’s configuration file (e.g., in your AI assistant’s settings). The server is designed to be launched on-demand by the client.

Add the following to your mcpServers configuration:

{
  "mcpServers": {
    "code-sandbox": {
      "command": "code-sandbox-mcp",
    }
  }
}

Provide Secrets and pass through environment variables

You can pass through environment variables to the sandbox by setting the --pass-through-env flag when starting the MCP server and providing the env when starting the server

{
  "mcpServers": {
    "code-sandbox": {
      "command": "code-sandbox-mcp",
      "args": ["--pass-through-env", "API_KEY,SECRET_TOKEN"]
      "env": {
        "API_KEY": "1234567890",
        "SECRET_TOKEN": "1234567890"
      }
    }
  }
}

Provide a custom container image

Открыть полный README на GitHub

Установка

npx @modelcontextprotocol/inspector
Новичок в MCP? Начните с руководства на mcpskill.org →

Конфигурация

{ "mcpServers": { "code-sandbox": { "command": "code-sandbox-mcp", } } }