Loading...

文章背景图

E2B 保姆级部署教程:给 AI 智能体一个安全的云沙箱跑代码

2026-11-09
1
- 字
- 分钟
|

e2b

[{"source":{"position":32,"lines":["https://github.com/e2b-dev/e2b"]},"target":{"position":32,"lines":["<a href="https://github.com/e2b-dev/e2b" target="_blank" rel="noopener">https://github.com/e2b-dev/e2b"]},"type":"CHANGE"},{"source":{"position":36,"lines":["https://e2b.dev/docs"]},"target":{"position":36,"lines":["<a href="https://e2b.dev/docs" target="_blank" rel="noopener">https://e2b.dev/docs"]},"type":"CHANGE"},{"source":{"position":52,"lines":["

  • 一个 E2B 账号 + API Key(去 https://e2b.dev/dashboard?tab=keys 申请);
  • "]},"target":{"position":52,"lines":["
  • 一个 E2B 账号 + API Key(去 <a href="https://e2b.dev/dashboard?tab=keys" target="_blank" rel="noopener">https://e2b.dev/dashboard?tab=keys 申请);
  • "]},"type":"CHANGE"},{"source":{"position":68,"lines":["
  • 在 https://e2b.dev/dashboard?tab=keys 拿 API Key;
  • "]},"target":{"position":68,"lines":["
  • 在 <a href="https://e2b.dev/dashboard?tab=keys" target="_blank" rel="noopener">https://e2b.dev/dashboard?tab=keys 拿 API Key;
  • "]},"type":"CHANGE"},{"source":{"position":159,"lines":["

    其他 SDK 高级参数(env vars、metadata、template)以官方文档 https://e2b.dev/docs 为准,本文不臆造。

    "]},"target":{"position":159,"lines":["

    其他 SDK 高级参数(env vars、metadata、template)以官方文档 <a href="https://e2b.dev/docs" target="_blank" rel="noopener">https://e2b.dev/docs 为准,本文不臆造。

    "]},"type":"CHANGE"},{"source":{"position":220,"lines":["

    自定义沙箱模板:默认沙箱是精简 Linux 镜像,缺的工具每次都 apt install 很慢。官方支持基于基础镜像打自定义 template(预装 pandas、ffmpeg、特定 Python 包),后续 Sandbox.create(template=...) 秒级启动,具体命令以 https://e2b.dev/docs 文档为准。

    "]},"target":{"position":220,"lines":["

    自定义沙箱模板:默认沙箱是精简 Linux 镜像,缺的工具每次都 apt install 很慢。官方支持基于基础镜像打自定义 template(预装 pandas、ffmpeg、特定 Python 包),后续 Sandbox.create(template=...) 秒级启动,具体命令以 <a href="https://e2b.dev/docs" target="_blank" rel="noopener">https://e2b.dev/docs 文档为准。

    "]},"type":"CHANGE"},{"source":{"position":235,"lines":["
  • 官方 README:https://github.com/e2b-dev/e2b
  • ","
  • 官方文档:https://e2b.dev/docs
  • ","
  • 自托管 Embed:https://github.com/e2b-dev/runtime/blob/main/embed/README.md
  • ","
  • Cookbook:https://github.com/e2b-dev/e2b-cookbook
  • "]},"target":{"position":235,"lines":["
  • 官方 README:<a href="https://github.com/e2b-dev/e2b" target="_blank" rel="noopener">https://github.com/e2b-dev/e2b
  • ","
  • 官方文档:<a href="https://e2b.dev/docs" target="_blank" rel="noopener">https://e2b.dev/docs
  • ","
  • 自托管 Embed:<a href="https://github.com/e2b-dev/runtime/blob/main/embed/README.md" target="_blank" rel="noopener">https://github.com/e2b-dev/runtime/blob/main/embed/README.md
  • ","
  • Cookbook:<a href="https://github.com/e2b-dev/e2b-cookbook" target="_blank" rel="noopener">https://github.com/e2b-dev/e2b-cookbook
  • "]},"type":"CHANGE"}]

    安装部署(实操步骤)

    1. 前置准备

    • 项目仓库:e2b-dev/e2b(https://github.com/e2b-dev/e2b)
    • 需要本机具备 Git;按项目语言准备对应运行时(Python / Node.js / Go / Java 等)
    • 建议先在本机或测试服务器上跑通,再部署到生产环境
    • 遇到依赖版本问题时,以仓库 README 与 Releases 说明为准

    2. 官方安装 / 启动命令(摘自项目 README,可直接复制执行)

    npm i e2b
    pip install e2b
    ### 4. Code execution with Code Interpreter
    
    If you need to execute code with [`runCode()`](https://e2b.dev/docs/code-interpreting?utm_source=github&utm_medium=referral&utm_campaign=readme&utm_content=E2B)/[`run_code()`](https://e2b.dev/docs/code-interpreting?utm_source=github&utm_medium=referral&utm_campaign=readme&utm_content=E2B), install the Code Interpreter SDK ([JavaScript](./packages/code-interpreter-js) / [Python](./packages/code-interpreter-python)):
    ### 5. Computer use with Desktop
    
    For mouse, keyboard, screenshot, application, and desktop streaming APIs, install the Desktop SDK ([JavaScript](./packages/desktop-js) / [Python](./packages/desktop-python)):

    3. 部署流程

    1. 克隆仓库:git clone https://github.com/e2b-dev/e2b
    2. 进入目录后按上面的官方命令安装依赖
    3. 参考 README 的配置说明填写配置文件或环境变量
    4. 按官方说明启动服务,确认监听端口与访问地址
    5. 浏览器访问验证功能,确认无报错后再开放外网

    4. 常见问题排查

    • 依赖安装失败:先升级包管理器,再确认运行时版本符合 README 要求
    • 启动报端口占用:修改配置中的端口或释放被占用端口
    • 页面打不开:检查防火墙 / 安全组是否放行对应端口
    • 功能异常:查看运行日志,对照 Issues 中同类问题处理

    5. 官方链接

    评论交流

    文章目录