This page uses a plain
Agent with code tools — ideal as a task-focused recipe. For the dedicated CodeAgent class with sandboxed generate/execute/review/refactor methods, see the Code Agent page.Quick Start
How It Works
Simple
Agents: 1 — Single agent with code tools handles writing and executing code.Workflow
- Receive code request
- Generate code
- Execute and test
- Return working solution
Setup
Run — Python
Run — CLI
Run — agents.yaml
Serve API
Advanced Workflow (All Features)
Agents: 1 — Single agent with memory, persistence, structured output, and session resumability.Workflow
- Initialize session for code project tracking
- Configure SQLite persistence for code history
- Generate and execute code with structured output
- Store code in memory for iterative development
- Resume session for code modifications
Setup
Run — Python
Run — CLI
Run — agents.yaml
Serve API
Monitor / Verify
Cleanup
Features Demonstrated
| Feature | Implementation |
|---|---|
| Workflow | Multi-step code development |
| DB Persistence | SQLite via memory_config |
| Observability | --verbose flag |
| Tools | execute_code, analyze_code |
| Resumability | Session with session_id |
| Structured Output | Pydantic CodeResult model |
Best Practices
Let the agent execute, then verify
Let the agent execute, then verify
Attach
execute_code so the agent runs its own output and catches errors before returning. Code that only looks right often fails on the first run.Enable reflection for tricky tasks
Enable reflection for tricky tasks
Set
reflection=True so the agent reviews and corrects its solution. This trades a few extra tokens for markedly higher first-try success on non-trivial code.Prefer the CodeAgent for sandboxed workflows
Prefer the CodeAgent for sandboxed workflows
When you need process isolation, timeouts, and language restrictions, use the dedicated
CodeAgent class instead of a plain Agent with tools.Never disable the sandbox on untrusted input
Never disable the sandbox on untrusted input
If you switch to
CodeAgent, keep sandbox=True in production. Executing model-generated code without isolation is a security risk.Related
The dedicated CodeAgent class with sandboxed execution.
Analyze data files with a data-focused agent.

