Choose an integration
Native ADK environment
Use Google’s built-in E2B environment for direct shell and file operations
Advanced E2B plugin
Give an ADK agent ready-made code, command, file, and background-process tools
Native: Google ADK environment
Google ADK includes the experimentalE2BEnvironment
for direct command execution and file access through ADK’s environment API. No
additional integration package is required.
execute, read_file, and write_file itself.
Advanced: E2B plugin
Thee2b-adk plugin exposes sandbox
operations as tools the model can call. It adds stateful code execution, shell
commands, file management, and background processes backed by the
E2B Code Interpreter. The plugin creates one sandbox lazily, shares it
across tool calls, and closes it with the ADK runner.
To use E2B with ADK:
- Create an
E2BPlugin. - Hand
plugin.get_tools()to yourAgentand register the plugin on theApp. - Run the agent — every tool call executes inside the sandbox, and the plugin creates and tears the sandbox down for you.
Install the dependencies
Install the plugin. It pulls in Google ADK and the E2B Code Interpreter SDK.Example: Data analysis agent
A good fit for a sandbox is analysis the model shouldn’t do in its head. Here the agent is given a raw dataset and a question. Rather than eyeballing the numbers, it writes the data to a file, runs real pandas against it, and reports figures it actually computed — the sandbox is a calculator it can’t fool.Create the plugin and agent
The plugin owns the sandbox. Pass its tools to theAgent and register it on the
App; the instruction is what makes the agent run code rather than guess.
Run the analysis
Run the agent inside anInMemoryRunner. The sandbox is created lazily on the
first tool call, kept alive while the agent works, and killed when the
async with block exits — you never manage it yourself.
sales.csv with write_file, then uses run_code to load it
with pandas, compute revenue-per-dollar and per-month totals, and answer in
prose — every number backed by an execution in the sandbox:
verbose=True to run_debug to also print each tool call and its result
as the agent works.
Full example
Example: Code generation agent
The same tools support a code generator that verifies its own work. The instruction tells the agent to execute every snippet in the sandbox before returning it, so what you get back has already run and passed its tests — no untested code reaches the user.Tools
plugin.get_tools() returns six tools, all sharing the plugin’s single sandbox
so state persists across calls. Each returns a dict with a success flag and
reports failures in the result rather than raising, so a bad call never aborts
the agent run. success means the tool ran: code that raised or a command
that exited non-zero still returns success: True with the failure captured in
error / exit_code — only a call that could not run at all returns
success: False.
Configuration
E2BPlugin accepts keyword-only options, all optional. Anything you don’t set
falls back to the E2B SDK’s own default — the plugin overrides none of them.
timeout (E2B’s default is 300s). An idle
gap longer than timeout still expires the sandbox under E2B’s default
lifecycle — pass
lifecycle={"on_timeout": {"action": "pause"}, "auto_resume": True} to pause
and auto-resume across idle gaps instead. See the
repository README
for the full option list.
Reference examples
Complete, runnable scripts live in the plugin repository.Data analysis agent
Compute real answers from a dataset with pandas in the sandbox
Code generator
Return only code that has been executed and tested