execute_python runs Python code inside an isolated sandbox and returns structured execution results. The agent exposes it automatically when code_execution="e2b" is enabled, so the model can calculate, process data, and generate one-off functionality without separate tools for every operation. section 8.2.3 section 8.5.5
The execution path connects agent configuration to a managed runtime:
- Store the sandbox in ExecutionContext.code_env so tools can access the current execution environment. section 8.2.3
- Enable code_execution="e2b" to autoregister execute_python during agent setup. section 8.2.3
Analyzing an Excel file
An agent can upload a spreadsheet, install required packages, and use pandas through execute_python to aggregate menu sales by city. State persists across sandbox calls, allowing later code to reuse earlier results while isolating package installation and execution from the host system. section 8.4.3
