Skip to main content

Dragen Logo

Dragen

CodeAct-style AI agents that write Python, not JSON.

PyPI version Crates.io License CI


Instead of making your LLM fill in JSON schemas one tool call at a time, Dragen gives it a Python sandbox. The agent writes real code — loops, branches, error handling, multi-step reasoning — all in one shot. That's the CodeAct pattern.

Code runs in a Littrs sandbox — a Python-to-bytecode compiler and stack VM embedded directly in your process. No containers, no cloud sandboxing services, no exec(). Zero ambient capabilities: no filesystem, no network, no env vars. The only way sandboxed code reaches the outside world is through tools you explicitly provide.

Installation

pip install dragen

Quick Start

import dragen

agent = dragen.Agent("moonshotai/kimi-k2.5")

@agent.tool
def search(query: str) -> str:
    """Search the web for information."""
    return f"Results for: {query}"

result = agent.run("Search for recent AI agent frameworks")
print(result)

Examples

Structured output with self-correction

Pass a schema and the agent retries until the output validates:

from pydantic import BaseModel

class Analysis(BaseModel):
    summary: str
    sentiment: str  # positive, negative, neutral
    confidence: float

agent = dragen.Agent("moonshotai/kimi-k2.5")
result = agent.run(
    "Analyze the sentiment of: 'This product is amazing!'",
    schema=Analysis.model_json_schema()
)
analysis = Analysis(**result)

Multi-agent pipeline with shared context

Agents pass typed data to each other through a shared Context:

from dragen import Agent, Context

ctx = Context()

# Planner researches and writes a plan
planner = Agent("moonshotai/kimi-k2.5").to_context(ctx, "plan")
planner.run("Create a research plan for: quantum computing trends")

# Writer reads the plan and produces content
writer = Agent("moonshotai/kimi-k2.5").from_context(ctx, "plan")
result = writer.run("Write a report based on the research plan")

Sandbox with tools, limits, and file access

sandbox = dragen.Sandbox(builtins=True)
sandbox.limit(max_instructions=50_000, max_recursion_depth=30)
sandbox.mount("data.csv", "./input/data.csv")

@sandbox.tool
def summarize(text: str) -> str:
    """Summarize text using an external API."""
    return call_summary_api(text)

agent = dragen.Agent("moonshotai/kimi-k2.5", sandbox=sandbox)
result = agent.run("Read data.csv and summarize its contents")

Recursive Language Model (RLM)

Process inputs far beyond the context window — the long input lives in the sandbox as a variable and the agent writes code to slice and summarize it across iterations:

sandbox = dragen.Sandbox(builtins=True)
sandbox["document"] = very_long_text  # e.g. 500K tokens

agent = dragen.Agent("moonshotai/kimi-k2.5", max_iterations=20, sandbox=sandbox)
result = agent.run("""
The variable `document` contains a very long research paper.
Extract all key findings, then synthesize them into a structured summary.
You can slice `document` with Python string indexing to read it in parts.
""")

Configuration

agent = dragen.Agent(
    "moonshotai/kimi-k2.5",
    max_iterations=10,
    temperature=0.7,
    max_tokens=4096,
    system="You are a helpful assistant"
)

Event Callbacks

agent = dragen.Agent("moonshotai/kimi-k2.5")

@agent.on_code
def on_code(code):
    print(f"Executing:\n{code}")

@agent.on_output
def on_output(output):
    print(f"Output: {output}")

@agent.on_finish
def on_finish(result):
    print(f"Done: {result}")

For the full feature reference, see DOCS.md. More examples in examples/.

License

Apache-2.0

Metadata

Release files for dragen 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for dragen 0.3.1
File
dragen-0.3.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
dragen-0.3.1-cp313-cp313-manylinux_2_38_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.38+ x86-64 Details
dragen-0.3.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
dragen-0.3.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
dragen-0.3.1-cp312-cp312-manylinux_2_38_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.38+ x86-64 Details
dragen-0.3.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
dragen-0.3.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
dragen-0.3.1-cp311-cp311-manylinux_2_38_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.38+ x86-64 Details
dragen-0.3.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
dragen-0.3.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
dragen-0.3.1-cp310-cp310-manylinux_2_38_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.38+ x86-64 Details
dragen-0.3.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details

Total release size: 63.5 MB

Release files / dragen-0.3.1-cp313-cp313-win_amd64.whl

Download URL dragen-0.3.1-cp313-cp313-win_amd64.whl
Size 4.2 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
43a1006801769cbf19d0472e094ba2251567e3023d40a5774a122bba19263232
BLAKE2b-256 checksum
How to use checksums
bfb0ee69f33af978af8a672d10ff0b12990ce961e344af9f56a55b603a86927f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp313-cp313-manylinux_2_38_x86_64.whl

Download URL dragen-0.3.1-cp313-cp313-manylinux_2_38_x86_64.whl
Size 7.1 MB
Tags CPython 3.13 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
221fff01ce615f832f02758e43b90d9ff6d9039ac7875717a184b25c79c2a24a
BLAKE2b-256 checksum
How to use checksums
8a1125ef74a951bdc719c362c34978be3a72a1b1f44bf00225dd144a74dee4f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL dragen-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cc2bd2e7c6cc8aa7ab128536da11c5ca711412755c158d7a9f348a9b3c7e86b1
BLAKE2b-256 checksum
How to use checksums
81b91087d679e3da19db9a681f479f61629a593747896ddafca24060ab466b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp312-cp312-win_amd64.whl

Download URL dragen-0.3.1-cp312-cp312-win_amd64.whl
Size 4.2 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
893eae35a13169c67c915d69a0a0c145c8f6f4f34d86417b8d82e2e56e05cf31
BLAKE2b-256 checksum
How to use checksums
40b7b6cff46dcb159272919fd84ec300bcff2b653ee6f23a3be17a8244cdcde6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp312-cp312-manylinux_2_38_x86_64.whl

Download URL dragen-0.3.1-cp312-cp312-manylinux_2_38_x86_64.whl
Size 7.1 MB
Tags CPython 3.12 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
6dea9c6c27d670c615c36cf4b3b7284d3685fd468034a9fe857e7ce9ba3ebd36
BLAKE2b-256 checksum
How to use checksums
b4701efca31285b12c48077fa4ec06e9ead3839b69d95838da319ae96f3a4720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL dragen-0.3.1-cp312-cp312-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bfe11ef3716d7621ffb8e358f864677b9e1b764a1a5b6f290eaee685a09c2f20
BLAKE2b-256 checksum
How to use checksums
5bdd1bf311ae142582ae09642450650e114ac95f578bbb5509851eca80a62bae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp311-cp311-win_amd64.whl

Download URL dragen-0.3.1-cp311-cp311-win_amd64.whl
Size 4.2 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
cc8d8c17c3e4f8319fa39fbbcf442652900db443aa32ffd8e5570dda23472acd
BLAKE2b-256 checksum
How to use checksums
39a931ca53fdc53cc24f9a1750494c5c65724edaa24016c659b92d3a2eb0a331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp311-cp311-manylinux_2_38_x86_64.whl

Download URL dragen-0.3.1-cp311-cp311-manylinux_2_38_x86_64.whl
Size 7.2 MB
Tags CPython 3.11 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
6ffddcd3fba23f4e99c426939545d094d5fbb51fd906bd6e3aa962251eb9df3a
BLAKE2b-256 checksum
How to use checksums
9016c21edf5b303d21c3611f46c85fb50eb99850326b24223f542af0db26d3a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL dragen-0.3.1-cp311-cp311-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3e0bc47a44e56354cd0c0b56999aab8e099ee093b633a63c3064facb4a45311f
BLAKE2b-256 checksum
How to use checksums
c0ee733019b7cdd07fef355c13629ecb2acc233c4d5670e039624abd6ab98991
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp310-cp310-win_amd64.whl

Download URL dragen-0.3.1-cp310-cp310-win_amd64.whl
Size 4.2 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
db263d421680c4512ac145c18a3fc918955b23cca1021787fd93c4105f011850
BLAKE2b-256 checksum
How to use checksums
9b7c0051209df268c13614aaac4640fb7ba3277bbdb19eb5e1a3075c587fcea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp310-cp310-manylinux_2_38_x86_64.whl

Download URL dragen-0.3.1-cp310-cp310-manylinux_2_38_x86_64.whl
Size 7.2 MB
Tags CPython 3.10 Linux glibc 2.38+ x86-64
SHA-256 checksum
How to use checksums
a9987914268ed4194097a5013e8f180c74d11ad402115796e63607f549209d8a
BLAKE2b-256 checksum
How to use checksums
158e13b86325b33a6772b0ae74688efcc3cc29bf85664b8d54e2d01eb0fc71d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / dragen-0.3.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL dragen-0.3.1-cp310-cp310-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1c1dcfc142e94e95f37a2cd7da8add0bbe082d883af781fa646bef61da46295c
BLAKE2b-256 checksum
How to use checksums
8ae1820f1bab17ba8fef04f147bad3b0ecc7bece1481237196f9c7079c599246
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.3.1 This release

12 release files

0.3.0

3 release files

0.2.1

3 release files

0.2.0

3 release files

0.1.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page