
philschmid/code-sandbox-mcp
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
philschmid/code-sandbox-mcp는 [[T0]에서 가져온 MCP 서버 후보입니다.
개요
philschmid/code-sandbox-mcp는 [[T0]에서 가져온 MCP 서버 후보입니다.
개요(AI 번역)
코드 샌드박스 MCP 서버는 경량의 STDIO 기반 모델 컨텍스트 프로토콜(MCP) 서버로, AI 어시스턴트와 LLM 애플리케이션이 컨테이너화된 환경에서 코드 스니펫을 안전하게 실행할 수 있도록 합니다. LLM 샌드박스 패키지를 사용하여 코드 스니펫을 실행합니다.
작동 원리:
- 컨테이너 세션(podman, docker 등)을 시작하고 세션이 열려 있는지 확인합니다.
code를 호스트의 임시 파일에 쓰는 것.- 이 임시 파일을 구성된
workdir의 컨테이너에 복사합니다. - 코드를 실행하기 위한 언어별 명령어를 실행합니다. 예: 파이썬
python3 -u code.py또는 자바스크립트node -u code.js - 컨테이너에서 출력 및 오류 스트림을 캡처합니다.
- 출력 및 오류 스트림을 클라이언트로 반환합니다.
- 용기를 멈추고 제거한다.
사용 가능한 도구들:
- run_python_code - 안전하고 격리된 샌드박스에서 파이썬 코드 일부를 실행합니다.
code(문자열, 필요): 실행할 파이썬 코드.- run_js_code - 안전하고 격리된 샌드박스에서 자바스크립트(Node.js) 코드 일부를 실행합니다.
code(문자열, 필수): 실행해야 할 자바스크립트 코드.
설치
시작하기 : 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",
}
}
}