
philschmid/code-sandbox-mcp
Developer toolsこのページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る
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サンドボックスパッケージを使用します。
仕組み:
- コンテナセッション(Podman、Dockerなど)を開始し、セッションが開かれていることを保証します。
codeをホスト上の一時ファイルに書き込む。- この一時ファイルを設定された
workdirのコンテナにコピーします。 - コードを実行するための言語固有のコマンドを実行します。例:Python
python3 -u code.pyやJavaScriptnode -u code.js - コンテナからの出力およびエラーストリームをキャプチャします。
- 出力およびエラーストリームをクライアントに返します。
- 容器を停止し取り出す。
利用可能なツール:
- 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:
- Starts a container session (podman, docker, etc.) and ensures the session is open.
- Writes the
codeto a temporary file on the host. - Copies this temporary file into the container at the configured
workdir. - Executes the language-specific commands to run the code, e.g. python
python3 -u code.pyor javascriptnode -u code.js - Captures the output and error streams from the container.
- Returns the output and error streams to the client.
- 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:
- Local Client Python example for running python code
- Gemini SDK example for running python code with the Gemini SDK
- Calling Gemini from a client example for running python code that uses the Gemini SDK and passes through the Gemini API key
- Local Client Javascript example for running javascript code
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
インストール
npx @modelcontextprotocol/inspector設定
{
"mcpServers": {
"code-sandbox": {
"command": "code-sandbox-mcp",
}
}
}