Description
E2BTools.__init__ calls Sandbox.create() immediately at construction time (line 49 in agno/tools/e2b.py). This causes several problems:
- Sandbox created before it's needed — if the agent never uses E2B tools in a session, the sandbox is wasted
- Multiple sandboxes on restart — every process restart creates new sandboxes while old ones linger until timeout (300s default)
- Cannot use with AgentOS —
AgentOS requires Agent instances at construction, which triggers E2BTools.__init__, which creates sandboxes before the app even starts serving requests
- No cleanup on shutdown —
E2BTools never calls sandbox.kill(), so sandboxes accumulate until timeout
Expected Behaviour
Sandbox should be created lazily on the first tool call (e.g., run_python_code, list_files, read_file_content), not in __init__. Something like:
def _get_sandbox(self):
if self.sandbox is None:
self.sandbox = Sandbox.create(api_key=self.api_key, timeout=self.timeout, **self.sandbox_options)
return self.sandbox
Also, E2BTools should provide a close() or shutdown() method that kills the sandbox.
Environment
- agno 2.5.11
- e2b-code-interpreter 2.6.0
- Python 3.14
Steps to Reproduce
- Create an
Agent with E2BTools in the tools list
- Register it with
AgentOS
- Observe that sandboxes are created immediately on startup, before any user request
- Restart the process — observe duplicate sandboxes in E2B dashboard
Description
E2BTools.__init__callsSandbox.create()immediately at construction time (line 49 inagno/tools/e2b.py). This causes several problems:AgentOSrequiresAgentinstances at construction, which triggersE2BTools.__init__, which creates sandboxes before the app even starts serving requestsE2BToolsnever callssandbox.kill(), so sandboxes accumulate until timeoutExpected Behaviour
Sandbox should be created lazily on the first tool call (e.g.,
run_python_code,list_files,read_file_content), not in__init__. Something like:Also,
E2BToolsshould provide aclose()orshutdown()method that kills the sandbox.Environment
Steps to Reproduce
AgentwithE2BToolsin the tools listAgentOS