跳到主要内容

智能体框架与 SDK

Agno

为 Agno 智能体提供运行代码的隔离沙箱。Agno 官方的 E2BTools 工具包会在 E2B 中运行智能体编写的 Python,而不是在运行 Agno 的机器上。

维护方
Agno
集成方式
以 E2BTools 形式内置于 agno
软件包
agno
语言
Python

配置

快速开始

将提示词粘贴到您的编程智能体中,或按以下步骤自行配置。

粘贴到您的编程智能体中

为这个 Agno 项目添加 E2B 沙箱。

  1. 1.使用项目的包管理器安装 agno 和 e2b_code_interpreter。
  2. 2.该工具包需要 E2B_API_KEY 环境变量。如果尚未设置,请向我索要 API 密钥(在 https://console.e2b.dev/?tab=keys 获取)。切勿将其硬编码。
  3. 3.按照 https://docs.e2b.dev/agents/agno 上的 Agno 指南,为我的智能体提供带有显式 include_tools 允许列表的 E2BTools,让它们编写的 Python 在 E2B 沙箱中运行。在 finally 块中调用 shutdown_sandbox()。
  4. 4.运行一次智能体,并展示来自沙箱的输出。

或自行配置

  1. 1. 安装依赖

    uv pip install agno e2b_code_interpreter openai
  2. 2. 设置 API 密钥

    export E2B_API_KEY="e2b_..."
    export OPENAI_API_KEY="..."
  3. 3. 将工具包交给智能体

    from agno.agent import Agent
    from agno.models.openai import OpenAIResponses
    from agno.tools.e2b import E2BTools
    
    e2b_tools = E2BTools(
        timeout=600,
        sandbox_options={"allow_internet_access": False},
        include_tools=["run_python_code"],
    )
    
    agent = Agent(
        name="Code Execution Sandbox",
        model=OpenAIResponses(id="gpt-5.4-mini"),
        tools=[e2b_tools],
        instructions=[
            "Use the E2B sandbox to execute Python code for calculations.",
            "Verify the result before responding.",
        ],
    )
  4. 4. 运行您的智能体

    try:
        agent.print_response(
            "Write Python code to generate the first 10 Fibonacci numbers."
        )
    finally:
        e2b_tools.shutdown_sandbox()

安全

沙箱中运行的内容

智能体编写的代码在隔离的沙箱中运行,与运行 Agno 的机器隔离。

  • 代码智能体通过 E2BTools 运行的 Python 和命令,在 E2B Code Interpreter 沙箱中执行。
  • 工具include_tools 限制智能体可以调用哪些函数。对于不受信任的智能体,请不要包含主机文件传输辅助函数。
  • 生命周期每个 E2BTools 实例对应一个沙箱,在多次调用之间复用。timeout 限制其存活时间;shutdown_sandbox() 将其结束。
  • 网络任务不需要联网时,sandbox_options={"allow_internet_access": False} 可切断出站访问。

已启动 30亿+ 个沙箱

为每个智能体 配一台机器