e2b-sandbox-mcp
E2B 沙盒 MCP 服务器
这是一个 MCP(模型上下文协议)服务器,它将 Claude Code 与 E2B 云沙盒连接起来,为您提供隔离的 Linux 虚拟机,以便在不触碰本地机器的情况下处理任何 GitHub 仓库。
功能介绍
该服务器为 Claude Code 提供了 29 种工具,用于创建云沙盒、克隆仓库、运行命令、管理文件以及执行 git 操作——所有这些都在一个安全、可丢弃的 Linux 环境中进行。
您的本地机器保持不变。 所有操作都在 E2B 沙盒虚拟机内完成。
Related MCP server: codex-cli-mcp-tool
Token 节省
通过 E2B 沙盒而不是本地 Bash 运行命令可以减少每次对话消耗的 Token。工具输出经过结构化和截断(每个流 100KB,总计 200KB),因此大型构建/测试输出不会淹没您的上下文窗口。
项目规模 | 示例 | 本地 Bash Token | E2B 沙盒 Token | 节省 |
小型 | Express API,约 10 个文件 | ~15K-25K | ~10K-18K | ~20-30% |
中型 | Next.js 应用,50-100 个文件 | ~50K-100K | ~25K-45K | ~40-55% |
大型 | Monorepo,500+ 个文件 | ~200K-500K+ | ~60K-120K | ~60-75% |
为何能扩展: 在 Monorepo 上执行本地 npm install 可能会将 1 万多行内容转储到上下文中。完整的测试套件会增加数千行。使用 E2B,这些输出会被限制和结构化。后台进程 (sandbox_exec_background) 仅返回进程 ID——零流式输出。目录列表限制为 1000 个条目。结果:您的上下文窗口保持可用状态,用于实际工作,而不是被终端噪音消耗。
使用场景
远程处理任何 GitHub 仓库
将任何仓库克隆到沙盒中,运行其构建和测试套件,进行更改并推送——无需在本地安装项目。
You: "Clone github.com/fastify/fastify, run the tests, and find why test X fails"
Claude Code:
→ sandbox_create
→ sandbox_git_clone "https://github.com/fastify/fastify"
→ sandbox_exec "npm install"
→ sandbox_exec "npm test"
→ sandbox_file_read (inspect failing test)
→ sandbox_file_write (apply fix)
→ sandbox_exec "npm test" (verify)安全实验
在一次性环境中尝试有风险的更改(依赖项升级、重大重构、迁移脚本)。如果出现故障,使用 sandbox_kill 并重新开始。
持久化开发会话
在一天工作结束时暂停沙盒,第二天恢复它,所有文件和状态保持不变。无需再从头开始重建环境。
You: "Pause this sandbox, I'll continue tomorrow"
Claude Code:
→ sandbox_pause (saves state)
Next day:
→ sandbox_resume (picks up where you left off)预览开发服务器
在沙盒中启动 Web 应用并获取公共 URL 以在浏览器中预览——无需端口转发或隧道。
You: "Start the dev server and give me a URL to preview it"
Claude Code:
→ sandbox_exec_background "npm run dev"
→ sandbox_get_url 3000
→ Returns: https://abc123-3000.e2b.dev多仓库并行工作
启动多个沙盒,克隆不同的仓库,同时处理它们。每个沙盒都是完全隔离的。
类似 CI 的干净测试
在全新的 Linux 环境中运行完整的测试套件。在推送到 CI 之前捕获“在我机器上能运行”的问题。
开源贡献
Fork 一个仓库,在沙盒中克隆它,进行更改,提交并推送到您的 Fork——无需本地项目设置。
在实时环境中进行代码审查
将 PR 分支克隆到沙盒中,运行测试,检查更改并验证行为——无需在本地检出该分支。
入门指南
先决条件
Node.js >= 18
已安装 Claude Code CLI
E2B API 密钥(提供免费层级)
GitHub 个人访问令牌(可选,用于私有仓库和推送)
1. 注册 Claude Code
无需单独安装——只需使用 npx 将 Claude Code 指向 npm 包:
claude mcp add e2b-sandbox -s user \
-e E2B_API_KEY=your-e2b-api-key \
-e GITHUB_TOKEN=your-github-token \
-- npx -y e2b-sandbox-mcp添加服务器后重启 Claude Code。
如果您更喜欢全局安装而不是 npx:
npm install -g e2b-sandbox-mcp
claude mcp add e2b-sandbox -s user \
-e E2B_API_KEY=your-e2b-api-key \
-e GITHUB_TOKEN=your-github-token \
-- e2b-sandbox-mcp2. 使用它
启动 Claude Code 并要求它处理任何仓库:
"Create a sandbox, clone https://github.com/expressjs/express, and run the test suite"
Claude Code 将自动调用 MCP 工具。
可用工具
沙盒生命周期
工具 | 描述 |
| 创建一个新的云沙盒(Linux 虚拟机) |
| 列出所有活动的沙盒 |
| 获取特定沙盒的详细信息 |
| 终止并销毁沙盒 |
| 延长沙盒的超时时间 |
| 暂停沙盒,保留其状态以供稍后使用 |
| 恢复之前暂停的沙盒 |
网络与文件传输
工具 | 描述 |
| 获取端口的公共 URL(在浏览器中预览开发服务器) |
| 获取预签名 URL 以将文件上传到沙盒 |
| 获取预签名 URL 以从沙盒下载文件 |
命令执行
工具 | 描述 |
| 运行 shell 命令并获取 stdout/stderr/退出代码 |
| 启动后台进程(开发服务器、监视器) |
| 列出所有带有 PID 的运行进程 |
| 通过 PID 杀死运行中的进程 |
文件操作
工具 | 描述 |
| 读取文件内容 |
| 写入/创建文件 |
| 列出目录内容 |
| 创建目录 |
| 删除文件或目录 |
| 获取文件元数据(大小、类型、权限) |
| 检查文件或目录是否存在 |
| 重命名或移动文件或目录 |
Git 操作
工具 | 描述 |
| 克隆仓库(支持使用 GITHUB_TOKEN 的私有仓库) |
| 获取工作树状态 |
| 暂存文件并提交 |
| 将提交推送到远程 |
| 从远程拉取最新更改 |
| 列出、创建或切换分支 |
| 初始化新的 git 仓库 |
环境变量
变量 | 必需 | 描述 |
| 是 | 您来自 e2b.dev/dashboard 的 E2B API 密钥 |
| 否 | 用于私有仓库访问和 |
架构
src/
├── index.ts # MCP server entry point (stdio transport)
├── types.ts # Shared types and error helpers
├── services/
│ └── sandbox-manager.ts # Sandbox registry (tracks active VMs)
└── tools/
├── sandbox.ts # Lifecycle tools
├── commands.ts # Command execution tools
├── filesystem.ts # File operation tools
└── git.ts # Git operation tools服务器管理活动沙盒实例的注册表。每个工具都通过 ID 引用沙盒,允许在多个隔离环境中同时工作。
重要说明
沙盒是真实的虚拟机。 命令在 E2B 云中的实际 Linux 机器上执行。
Git push 是真实的。 从沙盒推送会推送到实际的远程仓库。
沙盒会自动过期。 默认超时为 5 分钟。使用
sandbox_keep_alive进行延长。E2B 使用有成本。 查看 E2B 定价了解详情。提供免费层级。
沙盒与您的机器隔离,但与互联网不隔离。网络请求、git 推送和 npm 发布都是真实的。
许可证
MIT
Available Tools
29 toolssandbox_createA
Create a new E2B cloud sandbox (secure Linux VM). Returns a sandboxId to use with other tools.
Inputs: templateId, timeoutMs, metadata.
sandbox_download_urlA
Get a presigned URL to download a file from the sandbox. Use this to retrieve build artifacts, logs, or any file from the sandbox.
Inputs: sandboxId (required), path (required).
sandbox_execA
Execute a shell command in a sandbox and return stdout, stderr, and exit code. Use for running builds, tests, installs, or any CLI command.
Inputs: sandboxId (required), command (required), cwd, timeoutMs, +1 more.
sandbox_exec_backgroundA
Start a background process in a sandbox (e.g., dev server, file watcher). Returns immediately without waiting for completion.
Inputs: sandboxId (required), command (required), cwd, envs.
sandbox_file_existsA
Check if a file or directory exists in a sandbox. Returns true/false without throwing an error if not found.
Inputs: sandboxId (required), path (required).
sandbox_file_infoA
Get metadata about a file or directory in a sandbox (size, type, permissions).
Inputs: sandboxId (required), path (required).
sandbox_file_listC
List files and directories in a sandbox path.
Inputs: sandboxId (required), path.
sandbox_file_mkdirB
Create a directory (and parent directories) in a sandbox.
Inputs: sandboxId (required), path (required).
sandbox_file_readB
Read the contents of a file in a sandbox.
Inputs: sandboxId (required), path (required).
sandbox_file_removeC
Delete a file or directory in a sandbox.
Inputs: sandboxId (required), path (required).
sandbox_file_renameC
Rename or move a file or directory in a sandbox.
Inputs: sandboxId (required), oldPath (required), newPath (required).
sandbox_file_writeA
Write content to a file in a sandbox. Creates parent directories automatically. Overwrites if file exists.
Inputs: sandboxId (required), path (required), content (required).
sandbox_get_urlA
Get the public URL for a port running inside a sandbox. Use this to access dev servers, web apps, or any HTTP service running in the sandbox from a browser.
Inputs: sandboxId (required), port (required).
sandbox_git_branchB
Manage git branches: list, create, or switch branches in a sandbox repository.
Inputs: sandboxId (required), repoPath (required), action (required), branchName.
sandbox_git_cloneA
Clone a GitHub repository into a sandbox. Supports private repos when GITHUB_TOKEN is configured.
Inputs: sandboxId (required), repoUrl (required), path, branch, +1 more.
sandbox_git_commitB
Stage files and create a git commit in a sandbox repository.
Inputs: sandboxId (required), repoPath (required), message (required), files, +2 more.
sandbox_git_initB
Initialize a new git repository in a sandbox directory.
Inputs: sandboxId (required), path (required).
sandbox_git_pullC
Pull latest changes from a remote repository in a sandbox.
Inputs: sandboxId (required), repoPath (required), remote, branch.
sandbox_git_pushA
Push commits to a remote repository. Requires GITHUB_TOKEN for authentication.
Inputs: sandboxId (required), repoPath (required), remote, branch, +1 more.
sandbox_git_statusA
Get the git status of a repository in a sandbox (current branch, modified/staged/untracked files).
Inputs: sandboxId (required), repoPath (required).
sandbox_infoC
Get details about a specific sandbox.
Inputs: sandboxId (required).
sandbox_keep_aliveA
Extend a sandbox timeout to prevent it from being automatically terminated.
Inputs: sandboxId (required), timeoutMs (required).
sandbox_killA
Terminate and clean up a sandbox. The sandbox and all its data will be destroyed.
Inputs: sandboxId (required).
sandbox_listA
List all active E2B sandboxes managed by this server.
Inputs: no named parameters.
sandbox_pauseA
Pause a sandbox to preserve its state. The sandbox can be resumed later with sandbox_resume using the same sandbox ID. Paused sandboxes persist across sessions and do not count against timeout.
Inputs: sandboxId (required).
sandbox_process_killA
Kill a running process in a sandbox by its PID. Use sandbox_process_list to find the PID.
Inputs: sandboxId (required), pid (required).
sandbox_process_listA
List all running processes (commands and PTY sessions) in a sandbox. Shows PID, command, and arguments for each process.
Inputs: sandboxId (required).
sandbox_resumeA
Resume a previously paused sandbox. Reconnects to the sandbox and restores its state including filesystem and running processes.
Inputs: sandboxId (required), timeoutMs.
sandbox_upload_urlA
Get a presigned URL to upload a file to the sandbox. Send a POST request with the file as multipart/form-data to the returned URL.
Inputs: sandboxId (required), path.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 29 tools
Each tool targets a distinct operation on sandboxes (create, exec, file ops, git, lifecycle management, process control). No overlapping purposes; even similar operations like sandbox_exec vs sandbox_exec_background are clearly differentiated by synchronous vs background execution.
All tools follow the consistent pattern of `sandbox_<action>`, using snake_case. Actions are clear verbs (create, exec, list, kill, etc.). This provides a predictable and intuitive naming scheme.
29 tools is on the higher side but justified by the broad scope of sandbox management (execution, file system, git, process management, lifecycle). The count is reasonable for a comprehensive server, though could be slightly trimmed by merging some rare operations.
The tool set covers the full lifecycle of sandboxes: create, list, info, keep-alive, pause/resume, kill. It includes file operations (CRUD), execution (command + background), process management, git operations (init, clone, branch, status, commit, pull, push), and utilities like download/upload URLs. No obvious gaps for typical sandbox usage.
Maintenance
Related MCP Connectors
An MCP server that gives your AI access to the source code and docs of all public github repos
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Hosted YouTube MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseAqualityDmaintenanceMCP server that spawns autonomous Claude Code agents in GitHub repos, enabling task delegation with persistent state, multi-step workflows, and job monitoring.47161 npm2Apache 2.0
- AlicenseNot gradedqualityDmaintenanceAn MCP server that allows Claude Code to interact with the OpenAI Codex CLI.50 npm20MIT
- AlicenseAqualityDmaintenanceAn MCP server that gives Claude live access to your GitHub workspace — PR reviews, issue triaging, repo search, and weekly digest reports through natural language.7MIT
- AlicenseNot gradedqualityCmaintenanceA self-hosted MCP server that gives Claude access to your GitHub account — read files, browse repos, commit changes, and manage issues and pull requests, all from a conversation.330 npmISC