MCP Code Sandbox Server
MCP コードサンドボックスサーバー
隔離されたサンドボックス環境で安全なコード実行機能を提供する、拡張可能なメッセージ通信プロトコル(MCP)サーバーです。このサーバーはMCP標準に準拠しており、Claude for Desktopやその他のMCPクライアントと互換性があります。
特徴
コード実行用の隔離されたサンドボックス環境を作成する
Pythonコードを安全に実行する
ファイル操作(リスト、読み取り、書き込み)を実行する
サンドボックスにPythonパッケージをインストールする
抽象化されたコードインタープリタインターフェースを備えた拡張可能なアーキテクチャ
明確な関心の分離を備えたモジュール設計
Related MCP server: anthropic_skill
建築
サーバーはモジュール式の拡張可能なアーキテクチャで構築されています。
コアコンポーネント
抽象インタープリタインターフェース: 異なるコード実行バックエンドを統合できる
サンドボックス管理: サンドボックス環境を作成および管理するためのツール
コード実行: コードを実行し、パッケージをインストールするためのツール
ファイル操作: サンドボックス内のファイルを管理するためのツール
プロジェクト構造
├── src/
│ └── sandbox/
│ ├── __pycache__/
│ ├── e2b/
│ │ ├── __pycache__/
│ │ ├── __init__.py
│ │ ├── e2b_file_interface.py
│ │ └── e2b_interpreter.py
│ ├── __init__.py
│ ├── code_interpreter.py
│ ├── file_interface.py
│ └── interpreter_factory.py
├── tools/
│ ├── __pycache__/
│ ├── __init__.py
│ ├── code_execution_tools.py
│ ├── file_tools.py
│ └── sandbox_tools.py
├── main.py
├── .env
├── .gitignore
├── .python-version
├── pyproject.toml
├── README.md
└── uv.lock前提条件
Python 3.10以上
E2B API キー(デフォルトの E2B インタープリタ用)
インストール
このリポジトリをクローンします:
git clone https://github.com/yourusername/mcp-code-sandbox.git cd mcp-code-sandbox仮想環境をセットアップします。
# Using venv python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Or using uv (recommended) uv init uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate必要なパッケージをインストールします。
# Using pip pip install fastmcp python-dotenv e2b-code-interpreter # Or using uv uv add fastmcp python-dotenv e2b-code-interpreter環境変数を設定します。
# Create a .env file with the following variables E2B_API_KEY=your_e2b_api_key_here INTERPRETER_TYPE=e2b # Default, can be changed to other implemented interpreters
使用法
サーバーをスタンドアロンで実行する
コマンドラインから直接サーバーを実行できます。
python main.pyこれにより、stdio トランスポートを使用してサーバーが起動され、Claude for Desktop との互換性が確保されます。
Claude for Desktop と併用
Claude for Desktopの最新バージョンがインストールされていることを確認してください
Claude for Desktop の構成ファイルを開きます。
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
コード サンドボックス サーバーの構成を追加します。
{ "mcpServers": { "code-sandbox": { "command": "python", "args": [ "/ABSOLUTE/PATH/TO/main.py" ] } } }または
uvを使用している場合:{ "mcpServers": { "code-sandbox": { "command": "uv", "args": [ "--directory", "/ABSOLUTE/PATH/TO/PROJECT_DIRECTORY", "run", "main.py" ] } } }ファイルを保存し、Claude for Desktopを再起動します。
利用可能なツール
サーバーは次のツールを提供します。
サンドボックス管理
create_sandbox : 新しいサンドボックス環境を作成する
close_sandbox : サンドボックスを閉じてクリーンアップする
get_sandbox_status : サンドボックスのステータスを確認する
コード実行
execute_code : サンドボックスでPythonコードを実行する
install_package : Python パッケージをインストールする
create_run_close : サンドボックスを作成し、コードを実行し、クリーンアップするオールインワンツール
ファイル操作
list_files : サンドボックス内のファイルを一覧表示する
read_file : ファイルの内容を読み取る
write_file : ファイルにコンテンツを書き込む
upload_file : サンドボックスにファイルをアップロードする
新しいインタープリタによる拡張
システムは拡張性を考慮して設計されています。新しいコードインタープリターを追加するには、以下の手順に従ってください。
インタープリタ実装用に
src/sandbox/の下に新しいディレクトリを作成します。src/sandbox/code_interpreter.pyとsrc/sandbox/file_interface.pyで定義されたインターフェースを実装します。新しいインタープリタタイプを
src/sandbox/interpreter_factory.pyに追加します。環境変数
INTERPRETER_TYPEを新しいインタープリターに設定します
新しいインタープリターの実装例:
# src/sandbox/my_backend/my_interpreter.py
from src.sandbox.code_interpreter import CodeInterpreter, ExecutionResult
from src.sandbox.file_interface import FileInterface
class MyFileInterface(FileInterface):
# Implement the required methods
class MyInterpreter(CodeInterpreter):
# Implement the required methods
# Update src/sandbox/interpreter_factory.py to include your new interpreterモジュールの説明
サンドボックスコア ( src/sandbox/ )
code_interpreter.py: コードインタープリタの抽象基本クラスfile_interface.py: ファイル操作のための抽象インターフェースinterpreter_factory.py: コードインタープリタインスタンスを作成するためのファクトリー
E2B実装 ( src/sandbox/e2b/ )
e2b_interpreter.py: コードインタープリタのE2B実装e2b_file_interface.py: ファイル操作の E2B 実装
ツール ( tools/ )
sandbox_tools.py: サンドボックス管理用のツールcode_execution_tools.py: コード実行用のツールfile_tools.py: ファイル操作用のツール
主な用途
main.py: メインアプリケーションのエントリポイント
トラブルシューティング
問題が発生した場合:
選択したインタープリターの正しいAPIキーがあることを確認してください
詳細なエラーメッセージについてはログを確認してください
必要なパッケージがすべてインストールされていることを確認する
Claude for Desktop がスクリプトへの正しいパスで設定されていることを確認します
セキュリティに関する考慮事項
コード実行は安全のためサンドボックス環境で行われる
このサーバーを本番環境で信頼できないコードを実行するために使用しないでください
サーバーは現在認証を実装していません。信頼できる環境でのみ使用してください。
ライセンス
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Augments MCP Server - A comprehensive framework documentation provider for Claude Code
Shared memory and mail for your AI agents. Verified with Claude Code; other MCP clients in testing.
Related MCP Servers
- AlicenseBqualityDmaintenanceA secure MCP server for executing whitelisted shell commands with resource and timeout controls, designed for integration with Claude and other MCP-compatible LLMs.20389 npm7MIT
- AlicenseNot gradedqualityDmaintenanceA robust, lightweight Model Context Protocol (MCP) server designed to empower your AI Agents with context-awareness, safe execution sandboxes, and dedicated thought logs.ISC
- AlicenseNot gradedqualityDmaintenanceA local MCP server that connects Claude Desktop to execute custom local code, such as generating custom greetings.8 npmISC
- AlicenseAqualityFmaintenanceMCP server for running external coding agents as background tasks inside Claude Code. Supports multiple backends including Codex, Grok, GLM, DeepSeek, and more.7MIT