E2BTools toolkit gives an Agno agent an E2B sandbox for Python execution, file operations, commands, and web servers.
Install the dependencies
Install Agno, the E2B Code Interpreter SDK, and the OpenAI provider used in the example:Run an agent in an E2B sandbox
Create anE2BTools instance and pass it to the agent. The agent can use the toolkit to run Python code in an isolated E2B sandbox instead of on the machine running Agno.
Choose an explicit tool allowlist
Without an explicit allowlist,E2BTools can expose tools for code execution, file operations, filesystem access, commands, internet access, and sandbox management. Start with only the capabilities the agent needs:
include_tools allowlist limits callable function names, not their arguments or paths. The complete toolkit includes host-to-sandbox and sandbox-to-host file-transfer helpers: upload_file(file_path, sandbox_path=None) accepts a local path on the machine running Agno, while download_file_from_sandbox(sandbox_path, local_path=None) can write sandbox content to a local path on that machine. Do not expose these helpers to an untrusted agent unless your application enforces an allowlist of host paths or provides a safe wrapper that fixes or validates every host path.
Sandbox lifecycle
AnE2BTools instance creates one sandbox when it is initialized and reuses it for subsequent tool calls. Set timeout to a bounded value appropriate for the workload, and call shutdown_sandbox() when the agent no longer needs the sandbox. If you use include_tools, keep shutdown_sandbox in the allowlist or call it directly from your application during cleanup.
Python code and commands run inside the E2B sandbox, but the toolkit also contains host-side file-transfer helpers. Treat model-generated code and tool output as untrusted data, do not expose host secrets or unrestricted host paths, validate outputs before passing them to trusted systems, and prefer an explicit include_tools allowlist.
The tool allowlist does not control outbound network access from code running in the sandbox. Set sandbox_options={"allow_internet_access": False} when the workload does not need the internet. When it does, enable access deliberately and apply network restrictions.