E2B是一个开源基础设施,允许您在云中安全隔离的沙盒中运行AI生成的代码和e2b.dev网站
e2b.dev网站可能是当前最流行的沙盒网站,网址:E2B | The Enterprise AI Agent Cloud
E2B是e2b.dev网站所使用的开源代码。网址:https://github.com/e2b-dev/E2B
E2B是一个开源基础设施,允许在云中安全隔离的沙盒中运行AI生成的代码。可以使用JavaScript SDK或Python SDK启动和控制沙盒。
刚开始理解有误,以为可以自建沙盒服务,后来才知道,还是要调用e2b.dev网站的服务。所以一定要到网站注册和获得API key.
安装SDK
JavaScript / TypeScript
npm i @e2b/code-interpreter
python
pip install e2b-code-interpreter
获取E2B API key
- 注册Sign up to E2B here.
- 获得Get your API key here.
- 设置API key的环境变量Set environment variable with your API key
E2B_API_KEY=e2b_***
在E2B网站获得API key的页面,显示:Unnamed API Key
但是只能看见一部分key,这是怎么回事呢?
自己新创建了一个key:
使用E2B沙盒
Execute code with code interpreter inside Sandbox
JavaScript / TypeScript
import { Sandbox } from '@e2b/code-interpreter'const sandbox = await Sandbox.create() await sandbox.runCode('x = 1')const execution = await sandbox.runCode('x+=1; x') console.log(execution.text) // outputs 2
Python
from e2b_code_interpreter import Sandboxwith Sandbox() as sandbox:sandbox.run_code("x = 1")execution = sandbox.run_code("x+=1; x")print(execution.text) # outputs 2
竞品分析
CodeSandbox
- 功能:
CodeSandbox 是一个在线开发环境,支持前端、后端和全栈应用的开发。它提供沙盒化的运行环境,支持实时协作。 - 适用场景:
- 在线开发 React、Vue 等前端应用。
- 快速测试和分享代码。
- 优势:
- 支持多种框架和库。
- 提供实时协作功能。
- 官网地址:
CodeSandbox: Instant Cloud Development Environments
Replit
- 功能:
Replit 是一个在线编程环境,支持多种语言和框架。它提供沙盒化的运行环境,适合快速开发和测试代码。 - 适用场景:
- 在线代码编辑与运行。
- 快速原型开发。
- 优势:
- 支持团队协作。
- 提供丰富的模板和库。
- 官网地址:
Replit – Build apps and sites with AI