跳到主要内容

智能体框架与 SDK

Google ADK

为 Google ADK 智能体提供运行代码、Shell 命令和处理文件的隔离沙箱。可使用 ADK 内置的 E2BEnvironment,或用 e2b-⁠adk 插件为模型提供现成的沙箱工具。

维护方
E2B
集成方式
内置于 ADK,另有插件
软件包
e2b-adk
语言
Python

配置

快速开始

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

粘贴到您的编程智能体中

为这个 Google ADK 项目添加 E2B 沙箱。

  1. 1.使用项目的包管理器安装 e2b-adk。
  2. 2.该插件需要 E2B_API_KEY 环境变量。如果尚未设置,请向我索要 API 密钥(在 https://console.e2b.dev/?tab=keys 获取)。切勿将其硬编码。
  3. 3.按照 https://docs.e2b.dev/agents/google-adk 上的 Google ADK 指南操作。创建一个 E2BPlugin,将 plugin.get_tools() 提供给我的智能体,并在 App 上注册该插件,由 runner 创建和关闭沙箱。
  4. 4.运行一次智能体,并展示来自沙箱的输出。

或自行配置

  1. 1. 安装插件

    pip install e2b-adk
  2. 2. 设置 API 密钥

    export E2B_API_KEY="..."
    export GOOGLE_API_KEY="..."
  3. 3. 创建插件和智能体

    from google.adk.agents import Agent
    from google.adk.apps import App
    
    from e2b_adk import E2BPlugin
    
    plugin = E2BPlugin()
    agent = Agent(
        model="gemini-2.5-flash",
        name="data_analyst",
        instruction="You are a data analyst. Compute numbers by running real pandas with run_code.",
        tools=plugin.get_tools(),
    )
    app = App(name="data_analysis", root_agent=agent, plugins=[plugin])
  4. 4. 运行智能体

    from google.adk.runners import InMemoryRunner
    
    DATASET = """month,region,marketing_spend,revenue
    2024-01,North,12000,48000
    2024-02,North,15000,61000
    2024-01,South,8000,26000
    2024-02,South,11000,30000"""
    
    async with InMemoryRunner(app=app) as runner:
        await runner.run_debug(
            f"Here is marketing spend and revenue as CSV:\n\n{DATASET}\n\n"
            "Save it to sales.csv, then tell me which region converts spend into "
            "revenue more efficiently and which month performed best."
        )

安全

沙箱中运行的内容

智能体发起的工具调用在隔离的沙箱中运行,与运行 ADK 的机器隔离。

  • 代码run_code 在有状态的内核中运行代码,因此变量会在多次调用之间保留。
  • 工具六个工具共用一个沙箱:run_code、run_command、write_file、read_file、list_files 和 start_background_command。
  • 生命周期插件在第一次工具调用时创建沙箱,并在 runner 关闭时将其终止。每次调用都会延长超时时间。
  • 空闲间隔传入 lifecycle 并将 on_timeout 设为 pause、启用 auto_resume,即可在超过 timeout 的空闲间隔中保留沙箱。

已启动 30亿+ 个沙箱

为每个智能体 配一台机器