Tools
E2B Code Execution
Examples
- Introduction
- Getting Started
- Agents
- Teams
- Workflows
- Applications
Agent Concepts
- Multimodal
- RAG
- Knowledge
- Memory
- Async
- Hybrid Search
- Storage
- Tools
- DuckDuckGo Search
- Calculator
- Airflow Tools
- Apify Tools
- ArXiv Tools
- AWS Lambda Tools
- Baidu Search Tools
- Cal.com Tools
- Composio Tools
- Confluence Tools
- Crawl4ai Tools
- CSV Tools
- DALL-E Tools
- Desi Vocal Tools
- Discord Tools
- Docker Tools
- DuckDB Tools
- Email Tools
- E2B Code Execution
- Exa Tools
- Fal Tools
- File Tools
- Financial Datasets Tools
- Firecrawl Tools
- Giphy Tools
- GitHub Tools
- Google Calendar Tools
- Google Maps Tools
- Google Search Tools
- Hacker News Tools
- Jina Reader Tools
- Jira Tools
- Linear Tools
- Luma Labs Tools
- MLX Transcribe Tools
- Models Labs Tools
- Newspaper Tools
- Newspaper4k Tools
- OpenBB Tools
- Pandas Tools
- Postgres Tools
- PubMed Tools
- Python Tools
- Replicate Tools
- Resend Tools
- SearxNG Tools
- SerpAPI Tools
- Shell Tools
- Slack Tools
- Sleep Tools
- Spider Tools
- SQL Tools
- Tavily Tools
- Todoist Tools
- Twilio Tools
- Webex Tools
- Website Tools
- Wikipedia Tools
- X (Twitter) Tools
- YFinance Tools
- YouTube Tools
- Zendesk Tools
- Vector Databases
- Embedders
Models
- Anthropic
- AWS Bedrock
- AWS Bedrock Claude
- Azure AI Foundry
- Azure OpenAI
- Cohere
- DeepInfra
- DeepSeek
- Fireworks
- Gemini
- Groq
- Hugging Face
- Mistral
- NVIDIA
- Ollama
- OpenAI
- Perplexity
- Together
- xAI
- IBM
- LM Studio
- LiteLLM
- LiteLLM OpenAI
Tools
E2B Code Execution
Code
cookbook/tools/e2b_tools.py
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.e2b import E2BTools
e2b_tools = E2BTools(
timeout=600, # 10 minutes timeout (in seconds)
filesystem=True,
internet_access=True,
sandbox_management=True,
command_execution=True,
)
agent = Agent(
name="Code Execution Sandbox",
agent_id="e2b-sandbox",
model=OpenAIChat(id="gpt-4o"),
tools=[e2b_tools],
markdown=True,
show_tool_calls=True,
instructions=[
"You are an expert at writing and validating Python code using a secure E2B sandbox environment.",
"Your primary purpose is to:",
"1. Write clear, efficient Python code based on user requests",
"2. Execute and verify the code in the E2B sandbox",
"3. Share the complete code with the user, as this is the main use case",
"4. Provide thorough explanations of how the code works",
],
)
# Example: Generate Fibonacci numbers
agent.print_response(
"Write Python code to generate the first 10 Fibonacci numbers and calculate their sum and average"
)
# Example: Data visualization
agent.print_response(
"Write a Python script that creates a sample dataset of sales by region and visualize it with matplotlib"
)
# Example: Run a web server
agent.print_response(
"Create a simple FastAPI web server that displays 'Hello from E2B Sandbox!' and run it to get a public URL"
)
# Example: Sandbox management
agent.print_response("What's the current status of our sandbox and how much time is left before timeout?")
# Example: File operations
agent.print_response("Create a text file with the current date and time, then read it back")
Usage
1
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv .venv
source .venv/bin/activate
2
Create an E2B account
Create an account at E2B and get your API key from the dashboard.
3
Install libraries
pip install e2b_code_interpreter
4
Set your API Key
export E2B_API_KEY=your_api_key_here
5
Run Agent
python cookbook/tools/e2b_tools.py