PC

philschmid/code-sandbox-mcp

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

205 stars 21 forks 品質 65 トレンド 17MIT

philschmid/code-sandbox-mcpは、[[T0]からインポートされたMCPサーバー候補です。

概要

philschmid/code-sandbox-mcpは、[[T0]からインポートされたMCPサーバー候補です。

概要(AI 翻訳)

Code Sandbox MCP Serverは軽量でSTDIOベースのModel Context Protocol(MCP)サーバーであり、AIアシスタントやLLMアプリケーションがコンテナ化環境を利用して安全にコードスニペットを実行できるようにします。コードスニペットを実行するためにLLMサンドボックスパッケージを使用します。

仕組み:

  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クライアントでの利用

例:

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

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

GitHub で README 全文を見る

インストール

npx @modelcontextprotocol/inspector
MCP 初心者?mcpskill.org のガイドから始めましょう →

設定

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