E2B 是一套面向 AI 智能体的开源云端沙箱基础设施,让模型生成的代码在隔离环境中运行,不污染本地或生产系统。它提供 JavaScript 与 Python SDK,几行代码即可创建并控制沙箱、执行终端命令、读写文件;配套的 Code Interpreter SDK 可直接运行代码并取回结果,Desktop SDK 则提供鼠标、键盘、截图与应用操作等桌面自动化接口。项目以 Apache-2.0 协议开源,既可直接使用托管服务,也能借助 Terraform 在 AWS、GCP、Azure 或自有 Linux 机器上自部署。
pip install e2b

E2B is an open-source infrastructure that allows you to run AI-generated code in secure isolated sandboxes in the cloud. To start and control sandboxes, use our JavaScript SDK or Python SDK.
JavaScript / TypeScript
npm i e2b
Python
pip install e2b
E2B_API_KEY=e2b_***
JavaScript / TypeScript
import Sandbox from 'e2b'
const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('echo "Hello from E2B!"')
console.log(result.stdout) // Hello from E2B!
Python
from e2b import Sandbox
with Sandbox.create() as sandbox:
result = sandbox.commands.run('echo "Hello from E2B!"')
print(result.stdout) # Hello from E2B!
If you need to execute code with runCode()/run_code(), install the Code Interpreter SDK (JavaScript / Python):
npm i @e2b/code-interpreter # JavaScript/TypeScript
pip install e2b-code-interpreter # Python
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()
const execution = await sandbox.runCode('x = 1; x += 1; x')
console.log(execution.text) // outputs 2
For mouse, keyboard, screenshot, application, and desktop streaming APIs, install the Desktop SDK (JavaScript / Python):
npm i @e2b/desktop # JavaScript/TypeScript
pip install e2b-desktop # Python
import { Sandbox } from '@e2b/desktop'
const desktop = await Sandbox.create()
await desktop.launch('google-chrome')
const screenshot = await desktop.screenshot()
Visit E2B documentation.
Visit our Cookbook to get inspired by examples with different LLMs and AI frameworks.
Read the embed deployment guide to learn how to set up the E2B runtime on your own. The infrastructure is deployed using Terraform.
Supported cloud providers:
内容由编辑整理,部分信息来自 GitHub 与项目官网,版权归原作者所有。发现错误?报告问题