E2B Sandbox MCP
A Model Context Protocol server that enables AI assistants to create, control, and interact with virtual desktop environments through E2B's secure cloud sandboxes.
README
E2B Sandbox MCP Server
🚀 AI-Powered Computer Use Through Secure Cloud Sandboxes
A powerful Model Context Protocol (MCP) server that enables AI assistants to create, control, and interact with virtual desktop environments through E2B's secure cloud sandboxes. Perfect for AI agents that need to perform computer tasks, web automation, or visual testing.
✨ Features
- 🖥️ Virtual Desktop Management: Create Ubuntu 22.04 desktop sandboxes in seconds
- 🎮 Complete Computer Control: Click, type, drag, scroll, and keyboard shortcuts
- 📺 Live VNC Streaming: Real-time desktop viewing through secure web streams
- 📸 Screenshot Capture: AI-ready desktop screenshots for vision processing
- 🔄 Lifecycle Management: Automatic cleanup and resource management
- 🛡️ Secure Isolation: Completely isolated environments with no host access
- 🔧 MCP Standard: Fully compatible with Model Context Protocol
- ⚡ High Performance: Optimized for AI workloads and real-time interaction
🎯 Use Cases
- AI Agent Automation: Let AI agents perform complex computer tasks
- Web Scraping & Testing: Automated browser interactions and testing
- Application Testing: Visual regression testing and UI automation
- Data Entry Automation: Automate form filling and data processing
- Research & Analysis: AI-powered information gathering from desktop apps
- Training Data Generation: Capture interaction sequences for ML training
📋 Prerequisites
- Node.js (v18 or higher)
- E2B API Key (Free tier available)
- TypeScript knowledge (for development)
🚀 Quick Start
1. Installation
# Clone the repository
git clone https://github.com/your-username/e2b-sandbox-mcp.git
cd e2b-sandbox-mcp
# Install dependencies
npm install
# Build TypeScript
npm run build
2. Configuration
Create a .env file or set environment variables:
E2B_API_KEY=your_e2b_api_key_here
Get your E2B API key:
- Visit E2B Dashboard
- Sign up/log in
- Navigate to "API Keys"
- Create a new API key
3. Running the Server
# Start the MCP server
npm start
# Development mode with hot reload
npm run dev
# Debug mode
npm run inspect
4. MCP Client Integration
Add to your MCP configuration file (e.g., mcp.json):
{
"mcpServers": {
"e2b-sandbox": {
"command": "node",
"args": ["/PATH_TO/e2b-sandbox-mcp/dist/index.js"],
"env": {
"OPEN_AI_API_KEY": "YOUR_OPEN_AI_API_KEY",
"E2B_API_KEY": "YOUR_E2B_API_KEY"
}
}
}
}
📚 API Reference
MCP Tools
create_sandbox
Creates a new E2B desktop sandbox instance.
Parameters:
resolution(optional): Array of [width, height]. Default:[1920, 1080]timeout(optional): Timeout in milliseconds. Default:600000(10 minutes)
Example:
{
"name": "create_sandbox",
"arguments": {
"resolution": [1920, 1080],
"timeout": 600000
}
}
Response:
{
"sandboxId": "imy7xu1l122itq99pp4rn-9886af4b",
"streamUrl": "https://6080-sandbox-id.e2b.app/vnc.html?autoconnect=true&resize=scale",
"resolution": [1920, 1080],
"status": "created",
"message": "Sandbox created successfully"
}
execute_computer_action
Execute computer actions on the sandbox desktop.
Parameters:
sandboxId: The sandbox ID to execute action onaction: Action object with type and parameters
Supported Actions:
| Action Type | Description | Parameters |
|---|---|---|
click |
Click at coordinates | x, y, button (left/right/middle) |
double_click |
Double-click at coordinates | x, y, button |
type |
Type text | text |
keypress |
Press keyboard keys | keys (e.g., "Ctrl+c", "Return") |
move |
Move mouse cursor | x, y |
scroll |
Scroll vertically | scroll_y, x, y |
drag |
Drag from point A to B | path (array of {x, y} points) |
screenshot |
Take screenshot | None |
Examples:
// Click example
{
"name": "execute_computer_action",
"arguments": {
"sandboxId": "sandbox-id",
"action": {
"type": "click",
"x": 100,
"y": 200,
"button": "left"
}
}
}
// Type text example
{
"name": "execute_computer_action",
"arguments": {
"sandboxId": "sandbox-id",
"action": {
"type": "type",
"text": "Hello, World!"
}
}
}
// Keyboard shortcut example
{
"name": "execute_computer_action",
"arguments": {
"sandboxId": "sandbox-id",
"action": {
"type": "keypress",
"keys": "Ctrl+c"
}
}
}
// Drag example
{
"name": "execute_computer_action",
"arguments": {
"sandboxId": "sandbox-id",
"action": {
"type": "drag",
"path": [
{"x": 100, "y": 100},
{"x": 200, "y": 200}
]
}
}
}
get_stream_url
Get the VNC stream URL for viewing the desktop.
{
"name": "get_stream_url",
"arguments": {
"sandboxId": "sandbox-id"
}
}
get_screenshot
Capture a screenshot of the desktop.
{
"name": "get_screenshot",
"arguments": {
"sandboxId": "sandbox-id"
}
}
Response:
{
"screenshot": "base64-encoded-image-data",
"format": "png",
"timestamp": "2024-01-15T10:30:00Z"
}
cleanup_sandbox
Clean up and destroy a sandbox instance.
{
"name": "cleanup_sandbox",
"arguments": {
"sandboxId": "sandbox-id"
}
}
list_sandboxes
List all active sandbox instances.
{
"name": "list_sandboxes",
"arguments": {}
}
🏗️ Integration Examples
Basic Usage
import { MCPClient } from "@modelcontextprotocol/sdk/client/index.js";
class ComputerUseClient {
private mcpClient: MCPClient;
async createDesktopSession() {
// Create a new sandbox
const result = await this.mcpClient.callTool({
name: "create_sandbox",
arguments: {
resolution: [1920, 1080],
timeout: 600000,
},
});
const response = JSON.parse(result.content[0].text);
return {
sandboxId: response.sandboxId,
streamUrl: response.streamUrl,
};
}
async automateWebBrowsing(sandboxId: string, url: string) {
// Open Firefox browser
await this.mcpClient.callTool({
name: "execute_computer_action",
arguments: {
sandboxId,
action: { type: "keypress", keys: "Meta+t" },
},
});
// Type URL
await this.mcpClient.callTool({
name: "execute_computer_action",
arguments: {
sandboxId,
action: { type: "type", text: url },
},
});
// Press Enter
await this.mcpClient.callTool({
name: "execute_computer_action",
arguments: {
sandboxId,
action: { type: "keypress", keys: "Return" },
},
});
}
}
React Frontend Integration
import React, { useState, useEffect } from "react";
interface DesktopViewerProps {
streamUrl: string;
}
function DesktopViewer({ streamUrl }: DesktopViewerProps) {
return (
<div className="desktop-container">
<iframe
src={streamUrl}
className="w-full h-full border-0"
allow="clipboard-read; clipboard-write; fullscreen"
title="E2B Desktop Sandbox"
style={{ minHeight: "600px" }}
/>
</div>
);
}
function App() {
const [sandboxData, setSandboxData] = useState(null);
const createSandbox = async () => {
// Your MCP client call here
const response = await mcpClient.callTool({
name: "create_sandbox",
arguments: { resolution: [1920, 1080] },
});
setSandboxData(JSON.parse(response.content[0].text));
};
return (
<div className="app">
<button onClick={createSandbox} className="btn-primary">
Create Desktop Sandbox
</button>
{sandboxData && <DesktopViewer streamUrl={sandboxData.streamUrl} />}
</div>
);
}
AI Agent Integration
class AIComputerAgent {
constructor(private mcpClient: MCPClient) {}
async performTask(sandboxId: string, instruction: string) {
// 1. Take screenshot to understand current state
const screenshot = await this.mcpClient.callTool({
name: "get_screenshot",
arguments: { sandboxId },
});
// 2. Process with AI to determine next actions
const actions = await this.analyzeAndPlan(
instruction,
screenshot.content[0].text
);
// 3. Execute planned actions
for (const action of actions) {
await this.mcpClient.callTool({
name: "execute_computer_action",
arguments: { sandboxId, action },
});
// Small delay between actions
await new Promise((resolve) => setTimeout(resolve, 500));
}
}
private async analyzeAndPlan(instruction: string, screenshot: string) {
// Your AI logic here (OpenAI, Anthropic, etc.)
// Return array of computer actions
return [
{ type: "click", x: 100, y: 200, button: "left" },
{ type: "type", text: "Hello World" },
];
}
}
🏛️ Architecture
System Overview
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ AI Assistant │ │ MCP Client │ │ Your App │
│ │ │ │ │ │
│ • Claude │◄──►│ • Tool Calls │◄──►│ • Frontend │
│ • GPT-4 │ │ • Responses │ │ • Backend │
│ • Custom │ │ │ │ • API │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ E2B Sandbox MCP │
│ Server │
│ │
│ • Sandbox Mgmt │
│ • Action Exec │
│ • Stream URLs │
│ • Screenshots │
└─────────────────┘
│
▼
┌─────────────────┐
│ E2B Cloud │
│ Sandboxes │
│ │
│ • Ubuntu 22.04 │
│ • VNC Streaming │
│ • Isolation │
│ • Auto Cleanup │
└─────────────────┘
Key Components
- MCP Server: Handles tool calls and manages E2B API interactions
- Sandbox Manager: Creates, tracks, and cleans up sandbox instances
- Computer Use Tools: Executes mouse, keyboard, and system actions
- Stream Manager: Provides VNC URLs for real-time desktop viewing
- Action Executor: Translates MCP actions to E2B desktop commands
📁 Project Structure
e2b-sandbox-mcp/
├── src/
│ ├── index.ts # Main MCP server entry point
│ ├── sandbox-manager.ts # E2B sandbox lifecycle management
│ └── computer-use-tools.ts # Computer action implementations
├── examples/
│ ├── simple-test.js # Basic testing script
│ ├── client-integration.ts # Advanced MCP client example
│ └── web-integration/ # Web app integration example
├── dist/ # Compiled JavaScript output
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # This file
🧪 Testing
Run Examples
# Test basic functionality
npm test
# Run web integration example
cd examples/web-integration
npm install
npm start
Manual Testing
# Start MCP server in debug mode
npm run inspect
# In another terminal, test tool calls
node examples/simple-test.js
🔧 Development
Setup Development Environment
# Clone and setup
git clone https://github.com/your-username/e2b-sandbox-mcp.git
cd e2b-sandbox-mcp
# Install dependencies
npm install
# Set up environment
cp .env.example .env
# Edit .env with your E2B API key
# Start development server
npm run dev
Available Scripts
npm run build- Compile TypeScript to JavaScriptnpm run dev- Start development server with hot reloadnpm start- Start production servernpm run inspect- Start with Node.js debuggernpm test- Run test scriptsnpm run setup- Setup and test installation
Adding New Features
- New Computer Actions: Add to
src/computer-use-tools.ts - Enhanced Management: Modify
src/sandbox-manager.ts - API Extensions: Update
src/index.tswith new tool definitions
🐛 Troubleshooting
Common Issues
| Problem | Solution |
|---|---|
E2B_API_KEY not found |
Set environment variable or pass --e2b-api-key argument |
Sandbox creation fails |
Check E2B API key validity and account quota |
Actions not executing |
Verify sandbox is active with list_sandboxes |
Stream URL not working |
Ensure sandbox supports VNC (desktop template) |
High memory usage |
Implement proper sandbox cleanup after use |
Debug Mode
# Enable detailed logging
DEBUG=* npm run dev
# MCP-specific debugging
MCP_DEBUG=1 npm start
# Node.js inspector
npm run inspect
# Then open chrome://inspect in Chrome
API Limits
- E2B Free Tier: 100 hours/month sandbox usage
- Concurrent Sandboxes: 5 active instances (Free), more on paid plans
- Timeout Limits: Default 10 minutes, configurable up to 24 hours
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines.
Development Workflow
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Add tests for new functionality
- Ensure all tests pass:
npm test - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Code Style
- Use TypeScript for all new code
- Follow existing code formatting (Prettier)
- Add JSDoc comments for public APIs
- Include error handling and validation
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🔗 Links
🙏 Acknowledgments
- E2B for providing the cloud sandbox infrastructure
- Anthropic for the Model Context Protocol specification
- The open-source community for various tools and libraries used in this project
<div align="center">
⭐ Star this repo if you find it useful!
Made with ❤️ for the AI automation community
</div>
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。