CodeAgent — a specialised agent with sandboxed execution built in.
CodeAgent provides comprehensive code assistance including generation, execution in sandboxed environments, code review, explanation, refactoring, and bug fixing.
Quick Start
1
Simple Usage
Generate and run code with two calls.
2
With Configuration
Lock down the sandbox for production use.
How It Works
Installation
Basic Usage
Code Generation
Code Execution
Code Review
Configuration
CodeConfig Options
Methods
generate()
Generate code from natural language description.execute()
Execute code in a sandboxed environment.review()
Review code for issues and improvements.explain()
Explain what code does in plain language.refactor()
Refactor code to improve quality.fix()
Fix bugs in code.Async Usage
Example: Code Assistant
Example: Bug Fixer
Security
Sandbox Features
- Process isolation: Code runs in separate subprocess
- Timeout enforcement: Prevents infinite loops
- Output limiting: Prevents memory exhaustion
- Language restrictions: Only allowed languages can execute
Best Practices
Always keep the sandbox enabled
Always keep the sandbox enabled
Leave
sandbox=True for any untrusted or model-generated code. Disabling isolation in production lets arbitrary code touch your host — a serious security risk.Set a timeout that fits the task
Set a timeout that fits the task
A short
timeout stops runaway loops from hanging your process. Tune it to the longest legitimate run your code needs, not longer.Review before you execute
Review before you execute
Call
review() on generated code before execute(). Catching an obvious bug in review is cheaper than debugging a failed run.Always check return codes and stderr
Always check return codes and stderr
execute() returns return_code and stderr. Branch on them — a non-zero code means the run failed, and fix() can repair it using the error text.Related
A tool-based programming recipe using a plain Agent.
Analyze images and understand visual content.

