
philschmid/code-sandbox-mcp
Developer toolsЭта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал
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 для выполнения фрагментов кода.
Как это работает:
- Запускает контейнерную сессию (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-клиентом
Примеры:
Эта страница переведена автоматически. Технические детали смотрите в оригинале.
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",
}
}
}