# E2B — Secure Sandboxes for AI Code > E2B runs AI-generated code in isolated cloud sandboxes. Install the Python/JS SDK, set `E2B_API_KEY`, then execute commands safely inside a sandbox. ## Install Save as a script file and run: # E2B — Secure Sandboxes for AI Code > E2B runs AI-generated code in isolated cloud sandboxes. Install the Python/JS SDK, set `E2B_API_KEY`, then execute commands safely inside a sandbox. ## Quick Use 1. Install: ```bash pip install e2b ``` 2. Run: ```bash python -c "from e2b import Sandbox; print('e2b import ok')" ``` 3. Verify: - Create a sandbox and run `echo "Hello from E2B!"` using the README example --- ## Intro E2B runs AI-generated code in isolated cloud sandboxes. Install the Python/JS SDK, set `E2B_API_KEY`, then execute commands safely inside a sandbox. - **Best for:** agent builders who need to execute untrusted code with isolation (CI-like sandboxes) instead of running directly on the host machine - **Works with:** Python SDK (`pip install e2b`) or JS SDK (`npm i e2b`), E2B API key, sandbox command execution (repo examples) - **Setup time:** 12 minutes ### Quantitative Notes - Install: `pip install e2b` (repo) - Setup time ~12 minutes - GitHub stars (verified): see Source & Thanks --- ## Practical Notes Use E2B to separate *reasoning* from *execution*. Let your LLM plan the steps, but run risky commands in a sandbox with clean state. This is especially useful for agents that generate code, install packages, or process untrusted data. In production, standardize images/templates and capture logs + artifacts for auditability. **Safety note:** Isolation reduces risk, but you still need secret management—never bake API keys into prompts or artifacts. ### FAQ **Q: Is E2B self-hostable?** A: The README links to a self-hosting guide and infrastructure repo for running E2B on your own cloud. **Q: What can I run inside a sandbox?** A: Commands and code execution via SDK methods; start with shell commands, then add a code-interpreter SDK if needed (repo mentions). **Q: How do I control cost?** A: Reuse sandboxes when possible, keep jobs short, and scope execution to minimal steps per task. --- ## Source & Thanks > GitHub: https://github.com/e2b-dev/E2B > Owner avatar: https://avatars.githubusercontent.com/u/129434473?v=4 > License (SPDX): Apache-2.0 > GitHub stars (verified via `api.github.com/repos/e2b-dev/E2B`): 12,146 --- # E2B——为 AI 生成代码提供安全沙盒 > E2B 在云端隔离沙盒里运行 AI 生成代码。安装 Python/JS SDK 并设置 `E2B_API_KEY`,即可在 sandbox 内安全执行命令与运行代码,显著降低误操作与泄露风险。 ## 快速使用 1. 安装: ```bash pip install e2b ``` 2. 运行: ```bash python -c "from e2b import Sandbox; print('e2b import ok')" ``` 3. 验证: - Create a sandbox and run `echo "Hello from E2B!"` using the README example --- ## 简介 E2B 在云端隔离沙盒里运行 AI 生成代码。安装 Python/JS SDK 并设置 `E2B_API_KEY`,即可在 sandbox 内安全执行命令与运行代码,显著降低误操作与泄露风险。 - **适合谁(Best for):** 要执行不可信代码的 agent 开发者,希望用隔离沙盒(类似 CI 环境)替代直接在宿主机运行 - **兼容工具(Works with):** Python SDK(`pip install e2b`)或 JS SDK(`npm i e2b`)、E2B API key、在 sandbox 内执行命令(仓库示例) - **安装时间(Setup time):** 12 分钟 ### 量化信息 - 安装:`pip install e2b`(仓库) - 装机约 12 分钟 - GitHub stars(已核验):见「来源与感谢」 --- ## 实战要点 把 E2B 用在“思考”和“执行”的隔离上:LLM 负责计划,但高风险命令在干净的 sandbox 里跑。对会生成代码、装包或处理不可信数据的 agent 特别有用。上生产后建议标准化镜像/模板,并保留日志与产物,便于审计与复现。 **安全提示:** 隔离能降风险,但仍要做好密钥管理——不要把 API key 写进 prompt 或产物里。 ### FAQ **Q: E2B 能自建吗?** A: README 提供了 self-hosting 指南与基础设施仓库链接,可在你自己的云上部署。 **Q: sandbox 里能跑什么?** A: 可以通过 SDK 在 sandbox 内运行命令与代码;先从 shell 命令开始,必要时再接入 code-interpreter SDK(仓库提到)。 **Q: 怎么控制成本?** A: 尽量复用 sandbox、把任务拆小并缩短运行时间,每次只做必要步骤。 --- ## 来源与感谢 > GitHub:https://github.com/e2b-dev/E2B > Owner avatar:https://avatars.githubusercontent.com/u/129434473?v=4 > 许可证(SPDX):Apache-2.0 > GitHub stars(已通过 `api.github.com/repos/e2b-dev/E2B` 核验):12,146 --- Source: https://tokrepo.com/en/workflows/e2b-secure-sandboxes-for-ai-code Author: Agent Toolkit