Skip to content

E2B plugin for ADK

Supported in ADKPython

The e2b-adk plugin connects an ADK agent to E2B sandboxes. It exposes tools for code execution, shell commands, file operations, and long-running processes while managing the sandbox lifecycle for the agent.

Use cases

  • Secure code execution: Run agent-generated code in an isolated, stateful sandbox instead of on the host machine.
  • Shell command automation: Install packages, run builds, and inspect the sandbox filesystem with configurable timeouts and working directories.
  • File workflows: Write scripts or datasets, run them, and read generated results back into the agent.
  • Background processes: Start long-running commands such as development servers and optionally return a preview URL for an exposed port.

Prerequisites

Set both API keys before running the example:

export E2B_API_KEY="your-e2b-api-key"
export GOOGLE_API_KEY="your-google-api-key"

Installation

pip install e2b-adk

Use with agent

import asyncio

from e2b_adk import E2BPlugin
from google.adk.agents import Agent
from google.adk.apps import App
from google.adk.runners import InMemoryRunner


async def main() -> None:
    plugin = E2BPlugin()
    root_agent = Agent(
        model="gemini-flash-latest",
        name="sandbox_agent",
        instruction="Use the sandbox to run and verify code before answering.",
        tools=plugin.get_tools(),
    )
    app = App(name="e2b_app", root_agent=root_agent, plugins=[plugin])

    async with InMemoryRunner(app=app) as runner:
        await runner.run_debug(
            "Write and run Python code that calculates the 20th Fibonacci number."
        )


if __name__ == "__main__":
    asyncio.run(main())

The plugin creates a sandbox lazily on the first E2B tool call and closes it when the runner exits.

Available tools

Tool Description
run_code Execute code in a stateful kernel
run_command Run a shell command in the sandbox
write_file Write a file to the sandbox filesystem
read_file Read a file from the sandbox filesystem
list_files List files and directories at a path
start_background_command Start a long-running process and optionally return a preview URL

Configuration

The E2BPlugin constructor accepts optional settings such as template, envs, timeout, and lifecycle. Other supported E2B sandbox creation options are forwarded to the E2B SDK. See the configuration reference for the full option list.

Additional resources