
Dragen
CodeAct-style AI agents that write Python, not JSON.
When you ask an LLM to call tools via JSON schemas, you're asking it to work in a format it wasn't trained on. It can't loop over results, can't branch on conditions, can't compose tool outputs — it fills in one schema at a time and waits. But give it a Python sandbox and it writes code: loops, branches, error handling, multi-step reasoning — all in one shot.
That's the CodeAct pattern, and Dragen is a framework built around it. You register tools as Python functions, hand the agent a task, and it writes code to solve it. The code runs in a Littrs sandbox — a Python-to-bytecode compiler and stack VM that embeds directly into your application. No containers, no cloud sandboxing services, no exec().
Why not smolagents?
Smolagents pioneered CodeAct agents in the Python ecosystem, but its default local executor is a restricted interpreter — not a true sandbox. It blocks dangerous imports and restricts dunder attributes, but has known CVEs (CVE-2025-5120, CVE-2025-9959) that allow sandbox escapes through whitelisted modules. For real isolation, you need Docker, E2B, or Modal — each adding infrastructure, latency, and operational overhead.
Dragen takes a different approach. The Littrs sandbox compiles Python to bytecode and runs it on a stack-based VM with zero ambient capabilities — no filesystem, no network, no env vars, no dangerous imports. Resource limits are enforced at the VM level and cannot be caught by try/except. The only way sandboxed code can reach the outside world is through the tools you explicitly provide. All of this runs in-process: cargo add dragen or pip install dragen and you're done.
What you get
- Secure sandbox — Littrs with resource limits, file mounting, and custom modules. Details
- Structured output — JSON Schema validation with self-correction. Works with Pydantic. Details
- Multi-agent pipelines — shared
Contextfor typed data passing between agents. Details - Parallel execution —
agent.map(tasks)runs concurrent tasks on cloned agents. Details - Any LLM — OpenAI, Anthropic, Groq, Ollama, or any compatible API via Tanukie
- Observable — event callbacks for every step of the agent loop. Details
Installation
Rust
Python
Quick Start
Rust
use ;
use tool;
/// Search the web for information.
///
/// Args:
/// query: The search query
async
Python
=
"""Search the web for information."""
return f
=
Examples
Structured output with self-correction
Pass a schema and the agent retries until the output validates:
:
: # positive, negative, neutral
:
=
=
=
Multi-agent pipeline with shared context
Agents pass typed data to each other through a shared Context:
=
# Planner researches and writes a plan
=
# Writer reads the plan and produces content
=
=
Recursive Language Model (RLM)
RLMs let an LLM recursively call itself to process inputs far beyond its context window. The long input lives in the sandbox as a variable — the agent writes code to slice, examine, and summarize chunks, accumulating results across iterations:
=
= # e.g. 500K tokens
=
=
The agent writes code like chunk = document[0:5000], processes it, then chunk = document[5000:10000], accumulating findings in a list variable across iterations — recursively decomposing the input without ever exceeding its context window.
Custom sandbox with limits and file access
Pre-configure a sandbox with resource limits and mounted files:
=
=
=
For the full feature reference, see DOCS.md. More examples in examples/.
Citation
If you use Dragen in your research, please cite it as: