内容
# 安全网格起源执行
一个开源、轻量级且极其安全的 **模型上下文协议(MCP)服务器**,设计用于在高度受限的本地 Docker 容器中运行任意 Python、JavaScript(Node.js)和 Bash 代码。
该存储库允许 AI 代理(如 Claude Desktop、Antigravity 或 Cursor)测试和运行代码,而无需冒损坏主机系统的风险。
---
## 🔒 安全特性(严格的沙盒隔离)
当 AI 代理请求执行代码时,服务器:
1. **执行隔离:** 在容器内禁用所有网络访问(`network_mode="none"`),以防止数据泄露、反弹 Shell 或本地网络扫描。
2. **挂载只读工作区:** 将主机目录挂载为只读(`ro`)卷,确保脚本可以读取工作区上下文,但不能删除、重写或修改主机文件。
3. **应用 CPU 和内存上限:** 将内存消耗上限设置为 **256MB**,并将计算资源限制为 **1 个 CPU 核心**,以防止拒绝服务(DoS)攻击或内存泄漏。
4. **以非 root 用户运行:** 在容器内强制以受限用户(`sandboxuser`,UID `10001`)执行,以防止容器突破漏洞。
---
## 🚀 设置和安装
### 1. 先决条件
- **Python 3.10+**
- **Docker Desktop** (确保 Docker 守护进程在您的系统上运行)
### 2. 克隆和安装依赖项
```bash
git clone https://github.com/yourusername/secure-grid-genesis-execution.git
cd secure-grid-genesis-execution
pip install -r requirements.txt
```
### 3. 构建沙盒容器
构建隔离环境镜像:
```bash
docker build -t secure-grid-sandbox -f Dockerfile.sandbox .
```
### 4. 运行自动化隔离测试
运行测试脚本以验证沙盒是否正确阻止文件写入和网络连接:
```bash
python test_sandbox.py
```
---
## 🛠️ 注册 MCP 服务器
将以下内容添加到 AI 客户端的配置文件中以注册服务器。
### 对于 Claude Desktop
将以下内容添加到 `%APPDATA%\Claude\claude_desktop_config.json` (Windows)或 `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):
```json
{
"mcpServers": {
"secure-grid-genesis-execution": {
"command": "python",
"args": [
"C:\\path\\to\\secure-grid-genesis-execution\\secure_executor.py"
]
}
}
}
```
*(确保将路径替换为克隆存储库的绝对路径)
### 对于 Google Antigravity
将以下内容添加到 `~/.gemini/config/mcp_config.json`:
```json
{
"mcpServers": {
"secure-grid-genesis-execution": {
"command": "python",
"args": [
"C:\\path\\to\\secure-grid-genesis-execution\\secure_executor.py"
]
}
}
}
```
---
## 🛠️ 暴露的 MCP 工具
服务器向 AI 代理暴露了三个工具:
1. `execute_python(code)`:安全地执行 Python 代码片段。
2. `execute_node(code)`:在 Node.js 内安全地执行 JavaScript 代码。
3. `execute_bash(command)`:在沙盒 Linux 环境中运行 Shell 命令。