Skip to main content
Generate, run, review, and fix code with the CodeAgent — a specialised agent with sandboxed execution built in.
The 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

Code execution is sandboxed by default. Never disable sandbox mode in production environments with untrusted input.

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

Leave sandbox=True for any untrusted or model-generated code. Disabling isolation in production lets arbitrary code touch your host — a serious security risk.
A short timeout stops runaway loops from hanging your process. Tune it to the longest legitimate run your code needs, not longer.
Call review() on generated code before execute(). Catching an obvious bug in review is cheaper than debugging a failed run.
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.
A tool-based programming recipe using a plain Agent.
Analyze images and understand visual content.