Toolkits
E2B
E2BTools enable an Agent to execute code in a secure sandboxed environment with support for Python, file operations, and web server capabilities.
Prerequisites
The E2B tools require the e2b_code_interpreter
Python package and an E2B API key.
Example
The following example demonstrates how to create an agent that can run Python code in a secure sandbox:
cookbook/tools/e2b_tools.py
Toolkit Params
Parameter | Type | Default | Description |
---|---|---|---|
api_key | str | None | E2B API key. If not provided, uses E2B_API_KEY env var. |
run_code | bool | True | Whether to register the run_code function |
upload_file | bool | True | Whether to register the upload_file function |
download_result | bool | True | Whether to register the download_result functions |
filesystem | bool | False | Whether to register filesystem operations |
internet_access | bool | False | Whether to register internet access functions |
sandbox_management | bool | False | Whether to register sandbox management functions |
timeout | int | 300 | Timeout in seconds for the sandbox (default: 5 minutes) |
sandbox_options | dict | None | Additional options to pass to the Sandbox constructor |
command_execution | bool | False | Whether to register command execution functions |
Toolkit Functions
Code Execution
Function | Description |
---|---|
run_python_code | Run Python code in the E2B sandbox environment |
File Operations
Function | Description |
---|---|
upload_file | Upload a file to the sandbox |
download_png_result | Add a PNG image result as an ImageArtifact to the agent |
download_chart_data | Extract chart data from an interactive chart in results |
download_file_from_sandbox | Download a file from the sandbox to the local system |
Filesystem Operations
Function | Description |
---|---|
list_files | List files and directories in a path in the sandbox |
read_file_content | Read the content of a file from the sandbox |
write_file_content | Write text content to a file in the sandbox |
watch_directory | Watch a directory for changes for a specified duration |
Command Execution
Function | Description |
---|---|
run_command | Run a shell command in the sandbox environment |
stream_command | Run a shell command and stream its output |
run_background_command | Run a shell command in the background |
kill_background_command | Kill a background command |
Internet Access
Function | Description |
---|---|
get_public_url | Get a public URL for a service running in the sandbox |
run_server | Start a server in the sandbox and return its public URL |
Sandbox Management
Function | Description |
---|---|
set_sandbox_timeout | Update the timeout for the sandbox |
get_sandbox_status | Get the current status of the sandbox |
shutdown_sandbox | Shutdown the sandbox immediately |
list_running_sandboxes | List all running sandboxes |