沙盒 MCP 服务器
一个 MCP 服务器,提供隔离的 Docker 环境以执行代码。此服务器允许您:
使用任意 Docker 镜像创建容器
使用多种编程语言编写和执行代码
安装软件包并设置开发环境
在隔离的容器中运行命令
先决条件
Python 3.9 或更高版本
Docker 安装并运行
uv 包管理器(推荐)
Docker MCP 服务器(推荐)
安装
克隆此存储库:
使用 uv 创建并激活虚拟环境:
安装依赖项:
与 Claude Desktop 集成
打开Claude Desktop的配置文件:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
添加沙盒服务器配置:
将/absolute/path/to/sandbox_server替换为项目目录的实际路径。
重启Claude桌面
使用示例
基本用法
一旦连接到 Claude Desktop,您可以:
创建 Python 容器:
以不同的语言运行代码:
安装包并使用它们:
保存和重现环境
服务器提供了几种保存和重现开发环境的方法:
创建持久容器
创建容器时,您可以使其持久化:
这将创建一个容器:
Claude Desktop 关闭后仍继续运行
可以通过Docker直接访问
保留所有已安装的软件包和文件
服务器将提供以下说明:
直接访问容器(
docker exec)停止和启动容器
不再需要时删除
保存容器状态
设置好环境后,您可以将其保存为 Docker 镜像:
这将:
创建一个新的 Docker 镜像,其中包含以下内容:
已安装的软件包
创建的文件
配置更改
提供重复使用环境的说明
然后,您可以共享此图像或将其用作新容器的起点:
生成 Dockerfile
为了使您的环境完全可重现,您可以生成一个 Dockerfile:
生成的 Dockerfile 将包括:
基础镜像规范
创建的文件
附加设置步骤的模板
您可以使用此 Dockerfile 来执行以下操作:
与他人共享您的环境设置
版本控制您的开发环境
修改和定制构建过程
部署到不同的系统
推荐的工作流程
对于可重复的开发环境:
创建持久容器:
安装所需的软件包并设置环境:
测试您的设置:
保存状态:
导出 Dockerfile:
这为您提供了重新创建环境的多种选择:
直接使用保存的Docker镜像
通过修改 Dockerfile 进行构建
如果需要,可以访问原始容器
安全说明
所有代码都在隔离的 Docker 容器中执行
容器使用后自动移除
容器之间的文件系统是隔离的
主机系统访问受到限制
项目结构
可用工具
该服务器提供三个主要工具:
create_container_environment:使用指定的镜像创建一个新的 Docker 容器create_file_in_container:在容器中创建文件execute_command_in_container:在容器中运行命令save_container_state:将容器状态保存到持久容器export_dockerfile:导出docker文件以创建持久环境exit_container:完成后关闭容器以清理环境
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
为代码执行提供隔离的Docker环境,使用户能够创建和管理容器、执行多语言代码、保存和重现开发环境,确保安全性和隔离性。
Related Resources
Related MCP Servers
- -security-license-qualityFacilitates isolated code execution within Docker containers, enabling secure multi-language script execution and integration with language models like Claude via the Model Context Protocol.Last updated -3MIT License
- -security-license-qualityAn interactive Python code execution environment that allows users and LLMs to safely execute Python code and install packages in isolated Docker containers.Last updated -30Apache 2.0
- -security-license-qualityA secure Docker-based environment that allows AI assistants to safely execute code without direct access to the host system by running all code within isolated containers.Last updated -3
- -security-license-qualityEnables running arbitrary JavaScript code in isolated Docker containers with on-the-fly npm dependency installation, supporting both ephemeral one-shot executions and persistent sandbox environments.Last updated -52109