Modular framework for building autonomous coding agents with E2B sandboxes and OpenAI.
# Install as package (recommended)
pip install -e .
# Or install dependencies only
pip install -r requirements.txtcp .env.example .env
# Edit .env and add your API keys:
# OPENAI_API_KEY=your_key_here
# E2B_API_KEY=your_key_hereGet API keys:
- OpenAI: https://platform.openai.com/api-keys
- E2B: https://e2b.dev/
python examples/simple_example.py
python examples/sandbox_example.py
python examples/web_builder_example.pyagents/
βββ src/agents/ # Main package β
USE THIS
β βββ __init__.py
β βββ core/ # Core functionality
β β βββ agent.py # CodingAgent class
β β βββ tools.py # Tool implementations
β β βββ sandbox.py # E2B sandbox utilities
β βββ use_cases/ # Pre-configured agents
β βββ presets.py # 5 agent types
β
βββ examples/ # Ready-to-run examples
β βββ simple_example.py
β βββ sandbox_example.py
β βββ web_builder_example.py
β
βββ tests/ # Test suite
β βββ test_tools.py
β
βββ docs.md # E2B/OpenAI API reference
βββ project.ipynb # Jupyter notebook
βββ requirements.txt
βββ setup.py
from agents import CodingAgent, ToolRegistry, SandboxManager
from agents import create_data_analyzer, create_web_builderfrom openai import OpenAI
from agents import CodingAgent, ToolRegistry
client = OpenAI()
# Create tools
registry = ToolRegistry(use_sandbox=False)
registry.register_execute_code()
# Create agent
agent = CodingAgent(
client=client,
tools=registry.get_tools(),
tool_schemas=registry.get_schemas(),
system_prompt="You are a helpful Python assistant.",
max_steps=10
)
# Run query
messages, metadata = agent.run("Create a fibonacci function")from openai import OpenAI
from agents import create_data_analyzer, SandboxManager, display_images_from_metadata
client = OpenAI()
agent = create_data_analyzer(client)
with SandboxManager() as sbx:
messages, metadata = agent.run(
"Generate 100 random numbers and create a histogram",
sbx=sbx
)
# Display generated charts (in Jupyter)
display_images_from_metadata(metadata)from openai import OpenAI
from agents import create_web_builder, SandboxManager, display_web_app
client = OpenAI()
agent = create_web_builder(client)
with SandboxManager() as sbx:
agent.run("Create a calculator app", sbx=sbx)
display_web_app(sbx) # Opens in Jupyter5 ready-to-use agent types:
from agents import (
create_data_analyzer, # Data analysis & visualization
create_web_builder, # HTML/CSS/JS applications
create_code_tutor, # Programming education
create_data_scientist, # ML & statistical analysis
create_devops_agent, # Automation & deployment
)- Generate synthetic datasets
- Statistical analysis
- Create visualizations (matplotlib, seaborn)
- Process CSV/JSON data
- Build interactive web apps
- HTML/CSS/JS development
- Responsive designs
- Serve apps in sandbox
- Explain programming concepts
- Demonstrate with examples
- Debug and explain errors
- Teaching best practices
- Train ML models
- Feature engineering
- Hypothesis testing
- Model evaluation
- Write automation scripts
- Set up environments
- Create deployment pipelines
- System monitoring
CodingAgent - Main agent with iterative loop
- Conversation memory
- Tool execution
- Configurable max steps
- Verbose output option
simple_agent_loop() - Functional alternative
ToolRegistry - Manage tool configurations
register_execute_code()- Python code executionregister_write_file()- File writingregister_read_file()- File reading (sandbox only)
execute_tool() - Execute tools by name
SandboxManager - E2B sandbox lifecycle
- Context manager (auto cleanup)
- Create/connect/kill sandboxes
- Query by metadata
SandboxCodeExecutor - Code execution wrapper
Utilities:
display_images_from_metadata()- Show chartsserve_web_app()- Start HTTP serverdisplay_web_app()- Display in IFrame
from openai import OpenAI
from agents import CodingAgent, ToolRegistr
8000
y, SandboxManager
client = OpenAI()
# Custom system prompt
system_prompt = """You are a Python expert specializing in algorithms.
Help users implement efficient data structures."""
# Create custom tools
registry = ToolRegistry(use_sandbox=True)
registry.register_execute_code()
registry.register_write_file()
# Build agent
agent = CodingAgent(
client=client,
tools=registry.get_tools(),
tool_schemas=registry.get_schemas(),
system_prompt=system_prompt,
max_steps=10,
verbose=True
)
# Use it
with SandboxManager() as sbx:
agent.run("Implement a binary search tree", sbx=sbx)from agents import SandboxManager
# Create with custom settings
manager = SandboxManager(
timeout=7200, # 2 hours
metadata={"project": "my-app"}
)
# List running sandboxes
sandboxes = SandboxManager.list_running()
# Find by metadata
sandboxes = SandboxManager.find_by_metadata({"project": "my-app"})
# Reconnect to existing
manager.connect("sbx-abc123")agent = CodingAgent(...)
# Multiple queries with context
with SandboxManager() as sbx:
agent.run("Create a function to add numbers", sbx=sbx)
agent.run("Now modify it to handle strings", sbx=sbx)
agent.run("Add error handling", sbx=sbx)
# Reset memory
agent.reset()from agents import execute_tool
result, metadata = execute_tool(
name="execute_code",
args='{"code": "print(\'Hello\')"}',
tools=registry.get_tools(),
sbx=sandbox
)# Run tests
python -m pytest tests/
# Run specific test
python tests/test_tools.py
# With verbose output
pytest tests/ -v- API Reference: See docstrings in source code
- E2B + OpenAI Docs:
docs.md - Examples:
examples/directory - Jupyter Notebook:
project.ipynb
pip install --upgrade e2b-code-interpreter openai python-dotenv- Check
.envfile exists with valid keys - Verify keys are not expired
- Use
load_dotenv()before creating clients
- Increase timeout:
SandboxManager(timeout=7200) - Kill unused sandboxes:
manager.kill() - List running:
SandboxManager.list_running()
- Requires Jupyter notebook
- Install:
pip install ipython jupyter
Data Analysis: Synthetic datasets, statistical analysis, visualizations, data processing
Web Development: Interactive apps, landing pages, form validators, responsive layouts
Education: Teaching concepts, demonstrating algorithms, debugging, best practices
Data Science: ML models, clustering, feature engineering, model evaluation
DevOps: Automation scripts, environment setup, CI/CD pipelines, monitoring
Extend the framework:
- Add new tools in
src/agents/core/tools.py - Create agent presets in
src/agents/use_cases/presets.py - Add examples in
examples/ - Write tests in
tests/
MIT License - free to use and modify for your projects.