mcpField
M
MCP Sandbox

MCP Sandbox

本地服务
mcpsandbox.xyzAI 与智能体3945 周前更新

关于 MCP Sandbox

MCP Sandbox 是一个基于 Docker 隔离的 Python 代码执行 MCP 服务,允许用户和 LLM 在独立容器中运行代码并安装包。适合需要安全执行 Python 代码的开发者与 AI 应用。

主要功能

  1. 01Docker 容器隔离执行 Python 代码
  2. 02沙箱创建、列举与复用
  3. 03在沙箱中安装 Python 包并查询状态
  4. 04执行终端命令并返回输出与退出码
  5. 05向沙箱上传文件
  6. 06内置 Web UI 与可选 API Key 鉴权

适用场景

  1. 01让 LLM 在隔离环境中运行并验证 Python 代码
  2. 02在沙箱内安装依赖并执行数据处理脚本
  3. 03生成文件并通过链接获取结果

MCP 相关

该项目是 MCP 服务,通过 SSE 端点向 MCP 客户端暴露沙箱相关工具,例如 create_sandbox 与 execute_python_code。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

MCP Sandbox

MCP Sandbox 徽标

欢迎试用 mcp sandbox

Python Version License UV MCP

中文文档 | 英文

演示

演示

Python MCP Sandbox 是一款交互式 Python 代码执行工具,允许用户和大模型在隔离的 Docker 容器中安全地执行 Python 代码和安装软件包。

Viby

Viby 可与 mcp sandbox 配合使用

功能

  • 🐳 Docker 隔离:在隔离的 Docker 容器中安全运行 Python 代码
  • 📦 软件包管理:轻松安装和管理 Python 软件包,并支持自定义 PyPI 镜像
  • 📊 文件生成:支持生成文件并通过 Web 链接访问
  • 🔐 身份验证:为多用户环境提供可选的基于 API 密钥的身份验证
  • 🎨 Web 界面:内置 Web 界面,用于管理沙箱和查看执行结果
  • 🌐 SSE 支持:通过 Server-Sent Events 实现实时通信,以便集成 MCP

安装

# Clone the repository
git clone https://github.com/JohanLi233/python-mcp-sandbox.git
cd python-mcp-sandbox

# Install dependencies using uv
uv venv
uv sync

# Start the server
uv run main.py

默认的 SSE 端点为 http://127.0.0.1:8181/sse,你可以通过 SSE 使用 MCP Inspector 与其交互,也可以使用任何支持 SSE 连接的客户端。

配置

可在 config.toml 中自定义服务配置:

  • 主机:默认为 127.0.0.1(仅限本地主机)
  • 端口:默认为 8181
  • PyPI 镜像:配置你偏好的 Python 软件包索引镜像

若要允许外部访问,请在配置文件中将主机更改为 0.0.0.0。

可用工具
  1. create_sandbox:创建新的 Python Docker 沙箱,并返回其 ID,以供后续执行代码和安装软件包使用
  2. list_sandboxes:列出所有现有沙箱(Docker 容器),以便重复使用
  3. execute_python_code:在指定的 Docker 沙箱中执行 Python 代码
  4. install_package_in_sandbox:在指定的 Docker 沙箱中安装 Python 软件包
  5. check_package_installation_status:检查指定的 Docker 沙箱中是否已安装软件包或其安装状态
  6. execute_terminal_command:在指定的 Docker 沙箱中执行终端命令。参数:sandbox_id(字符串)、command(字符串)。返回 stdout、stderr、exit_code。
  7. upload_file_to_sandbox:将本地文件上传到指定的 Docker 沙箱。参数:sandbox_id(字符串)、local_file_path(字符串)、dest_path(字符串,可选,默认值:/app/results)。

项目结构

python-mcp-sandbox/
├── main.py                    # Application entry point
├── requirements.txt           # Project dependencies
├── Dockerfile                 # Docker configuration for Python containers
├── results/                   # Directory for generated files
├── mcp_sandbox/               # Main package directory
│   ├── __init__.py
│   ├── models.py              # Pydantic models
│   ├── api/                   # API related components
│   │   ├── __init__.py
│   │   └── routes.py          # API route definitions
│   ├── core/                  # Core functionality
│   │   ├── __init__.py
│   │   ├── docker_manager.py  # Docker container management
│   │   └── mcp_tools.py       # MCP tools
│   └── utils/                 # Utilities
│       ├── __init__.py
│       ├── config.py          # Configuration constants
│       ├── file_manager.py    # File management
│       └── task_manager.py    # Periodic task management
└── README.md                  # Project documentation

提示词示例

I've configured a Python code execution sandbox for you. You can run Python code using the following steps:

1. First, use the "list_sandboxes" tool to view all existing sandboxes (Docker containers).
   - You can reuse an existing sandbox_id if a sandbox exists, do not create a new one.
   - If you need a new sandbox, use the "create_sandbox" tool.
   - Each sandbox is an isolated Python environment, and the sandbox_id is required for all subsequent operations.

2. If you need to install packages, use the "install_package_in_sandbox" tool
   - Parameters: sandbox_id and package_name (e.g., numpy, pandas)
   - This starts asynchronous installation and returns immediately with status

3. After installing packages, you can check their installation status using the "check_package_installation_status" tool
   - Parameters: sandbox_id and package_name (name of the package to check)
   - If the package is still installing, you need to check again using this tool

4. Use the "execute_python_code" tool to run your code
   - Parameters: sandbox_id and code (Python code)
   - Returns output, errors and links to any generated files
   - All generated files are stored inside the sandbox, and file_links are direct HTTP links for inline viewing

Example workflow:
- Use list_sandboxes to check for available sandboxes, if no available sandboxes, use create_sandbox to create a new one → Get sandbox_id
- Use install_package_in_sandbox to install necessary packages (like pandas, matplotlib), with the sandbox_id parameter
- Use check_package_installation_status to verify package installation, with the same sandbox_id parameter
- Use execute_python_code to run your code, with the sandbox_id parameter

Code execution happens in a secure sandbox. Generated files (images, CSVs, etc.) will be provided as direct HTTP links, which can viewed inline in the browser.

Remember not to use plt.show() in your Python code. For visualizations:
- Save figures to files using plt.savefig() instead of plt.show()
- For data, use methods like df.to_csv() or df.to_excel() to save as files
- All saved files will automatically appear as HTTP links in the results, which you can open or embed directly.

MCP 配置示例

以下是 Claude Desktop 的配置示例:

{
  "mcpServers": {
    "mcpSandbox": {
      "command": "npx",
      "args": ["-y", "supergateway", "--sse",  "http://127.0.0.1:8181/sse"]
    }
  }
}

如果启用了身份验证,请添加 API 密钥:

{
  "mcpServers": {
    "mcpSandbox": {
      "command": "npx",
      "args": ["-y", "supergateway", "--sse",  "http://127.0.0.1:8181/sse?api_key=<YOUR_API_KEY>"]
    }
  }
}

在线演示的 MCP 配置示例

{
  "mcpServers": {
    "mcpSandbox": {
      "command": "npx",
      "args": ["-y", "supergateway", "--sse",  "http://115.190.87.78/sse?api_key=<API_KEY>"]
    }
  }
}

根据你的环境按需修改 serverUrl。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。