# Bounded Loops: Loop Engineering You Can Actually Run

An AI coding agent can tell you it finished when it did not. Bounded Loops runs your agent until a check it can neither edit nor grade says the work actually passes, and stops at a limit you declared before the run started. Three words carry the whole idea. The gate is the check that decides pass or fail — a command, a test suite, a schema, never the agent; the agent's own "I'm done" is written to the record and ignored. The bound is a limit declared up front: attempts, tokens, wall-clock, laps without progress. The ledger is the append-only, hash-chained file of what happened, and `bl verify` re-checks it, so "it passed" is something you confirm rather than trust. The accompanying paper proves three guarantees — that a run finishes, does not drift, and does not overspend — and then measures the gates themselves against a held-out mutant corpus, because a proof about gates is worth what the gates are worth.

Status: live
Licence: Apache-2.0
Source: https://github.com/qualixar/bounded-loops
Paper: https://arxiv.org/abs/2609.27871
URL: https://qualixar.com/products/bounded-loops

## Install

```bash
pip install bounded-loops
```

## Features

- **Nine Bounds + Kill Switch**: Iteration and stall limits, scratch sandbox with symlinks refused, input quarantine excluding key material, output schema gate, per-lap tracing, regression evaluation, token budget, human approval, wall-clock limit. BOUNDED_LOOPS_KILL is checked before every lap; gate commands are tokenized and run without a shell.
- **The Gate Decides, Not the Agent**: The domain rule lives in one file and holds regardless of runner, gate, or storage backend. A gate the worker cannot write to is the only thing that can end a loop — pytest, a JSON Schema, a command, a security scanner. The agent's claim is recorded and ignored.
- **69 Loop Packages, 65 Keyless**: Finance, legal, retail, operations, enterprise and ERP, security, testing, content, research, business, healthcare, and software. They ship inside the wheel, so `bl loops install` copies one into your project with nothing downloaded — it works offline.
- **Vacuity and Self-Attestation, Measured**: Two defect classes let a sound-looking check pass anything: a check satisfied by the absence of the thing it checks, and a check whose subject supplied the value it is applied to. Turned on its own 69-loop catalogue, the instrument found 47 such gates in code that had shipped and passed review.
- **A Ledger You Can Re-Verify**: The receipt log is the sole durable state; the CLI, monitor, MCP server and Arena report are projections of it and hold none of their own. A third party holding only the run directory can check that no node reached DONE without a gate verdict — and the released verifier does exactly that.
- **Bring Your Own Agent**: Works with Claude Code, OpenAI Codex, Antigravity, or no agent at all. Ports-and-adapters throughout, with one composition module permitted to wire an adapter to a port — enforced by an import-graph walk that counts function-local and dynamic imports.

## Use cases

- Verify every case citation in a legal brief is real
- Reconcile ledgers and 3-way-match invoices in finance
- Gate insecure config (secrets, CORS, JWT alg, Dockerfile) in security review
- Keyless CI loops that stop only when a real gate passes
- Human-gated (L2/L3) agent loops for regulated industries
- Run the same bounded loop across Claude Code, Codex, and agent frameworks

## Who it is for, and who it is not for

### A good fit

- Developers who run Claude Code, Codex, Hermes or Antigravity on tasks with a checkable finish (a failing test, a schema, a lint rule) and are tired of an agent reporting success while the check still fails.
- Teams who need an attempt, token or time limit set before the run and enforced by the engine, with a record they can re-verify afterwards.
- Anyone building multi-step agent pipelines who needs fan-out, joins, repair routes and human approval before an irreversible step. The graph engine covers those.

### Probably not a fit

- Your task has no machine-checkable finish. The gate is a command, a test suite or a schema, and without one there is nothing independent to run.
- You want a hosted service. It is a local engine and CLI.
- You need OS-level isolation outside macOS for graph runs. Per the README, bl graph run --execute needs macOS; every other command runs anywhere.

## Quick start

Run in a clean environment on 24 Nov 2026; the output below is real.

No API key needed: the worker is a stub and the gate is real pytest. The commands are from the README. Run in a clean virtual environment on 24 Nov 2026 (bounded-loops 0.7.7 from PyPI, Python 3.13), the loop finished with the output below.

Install, fetch a shipped loop, run it:

```bash
python -m pip install bounded-loops
bl loops install bug-fix-red-green --dest ./loops
bl run loops/bug-fix-red-green --yes --run-id first-proof  # stub worker, real pytest gate
```

Output (ledger path omitted):

```text
[bounded-loops] About to run loop 'bug-fix-red-green':
  runner : stub
  gate   : pytest -q
✓ [DONE] gate-passed (laps: 1)
Gate verified: the independent acceptance gate passed after 1 lap.
```

See the failure it prevents:

```bash
./loops/bug-fix-red-green/wreck.sh     # the ungated version: exits claiming success
bl run loops/bug-fix-red-green --yes   # the same task, gated: pytest decides
```

The README says the wheel ships 69 loops, 65 of them keyless, and the repository adds seven digest-pinned graphs.

Source: [Bounded Loops README: Quickstart and Why you would want this](https://github.com/qualixar/bounded-loops#readme)

## How it compares

Three ways to get an agent to keep working until it is done. Star counts are from the GitHub API on 24 Nov 2026; Bounded Loops has 5.

Choose Bounded Loops when "done" must be decided by something the worker cannot edit or grade, and you want limits declared before the run plus a hash-chained record to check later. It is young, with one maintainer and 5 stars.

This product: 5 GitHub stars, licence Apache-2.0.

### [Ralph](https://github.com/snarktank/ralph#readme)

22,337 GitHub stars; licence MIT.

- What it is: A shell-based loop that runs Amp or Claude Code repeatedly, with a fresh context each time, until all items in a PRD file are complete. Memory persists through git history, progress.txt and prd.json.
- Choose it when: You want the simplest possible loop and trust the agent to report which items are complete. It is a pattern with a script, not an independent gate.

### [LangGraph](https://github.com/langchain-ai/langgraph#readme)

45,352 GitHub stars; licence MIT.

- What it is: A low-level orchestration framework for stateful agents with durable execution and human-in-the-loop controls.
- Choose it when: You are building the agent itself and want a mature graph runtime. The Bounded Loops paper notes that durable-execution platforms bound retries and time, but their checker usually lives in the same codebase as the work. Four shipped loops require a framework package: langgraph, crewai, agent-framework or google-adk.

### [A test in your own harness](https://github.com/qualixar/bounded-loops#readme)

no GitHub repo of its own; licence Yours.

- What it is: Many teams already stop an agent when their own check passes. That works as long as the check really checks something.
- Choose it when: You trust your own gates. The paper's finding is the reason to measure them: its instrument found 47 vacuous gates among 69 shipped loops, meaning checks that pass because the thing they check is absent.

The paper evaluates v0.6.6; the current software is newer, and later changes are not paper results. The zero false accepts over 209 destroying mutants (alpha at most 1.8%, Wilson 95%) is, in the paper's own words, saturation and not quality: a fresh operator family on frozen gates recovered a 23.3% false-accept rate.

## Proof and links

### Papers

- [Bounded Loops: Pre-Run Spend Bounds, Proved Termination, and Verified Completion for Agent Harnesses (arXiv:2609.27871)](https://arxiv.org/abs/2609.27871)

### Posts

- [Bounded Loops & Graphs: Verified AI Agent Completion](https://qualixar.com/research/blog/bounded-loops-graphs-verifiable-ai-agent-completion)
- [Loop Engineering: The Inner Loop, the Outer Loop, and the Gate](https://qualixar.com/research/blog/loop-engineering-inner-outer-loop-gate)

### Guides

- [What Is Harness Engineering? A Guide for AI Agents](https://qualixar.com/learn/guides/harness-engineering)
- [Loop Engineering — The Complete Guide](https://qualixar.com/learn/guides/loop-engineering-complete-guide)
- [The Bounded Loop — A Field Guide to AI Reliability Engineering](https://qualixar.com/learn/guides/bounded-loops-workbook)

### Films

- [Why AI agents say "done" when the work isn't: bounded loops and graphs](https://qualixar.com/watch/why-ai-agents-say-done-when-the-work-isnt-bounded-loops-graphs-research-isiyvpmr1p4)
- [Loop Engineering Vol. 1: the inner loop, the outer loop and the gate](https://qualixar.com/watch/loop-engineering-vol-1-the-inner-loop-the-outer-loop-and-the-gate-what-nobody-explains-4uda7m_cwuk)
- [Loop Engineering Vol. 2: your agent will lie that it is done](https://qualixar.com/watch/agent-will-lie-done)
- [Stop prompting your AI agents: build loops that cannot wreck your work](https://qualixar.com/watch/stop-prompting-ai-agents)

## Sources

- bounded-loops runs your agent until a check it cannot edit or grade passes, stops at a limit set before the run, and leaves a hash-chained record that can be re-verified. (https://github.com/qualixar/bounded-loops#readme)
- Works with Hermes, Claude Code, OpenAI Codex, Antigravity, or no agent at all. (https://github.com/qualixar/bounded-loops#readme)
- Install and run commands: pip install bounded-loops; bl loops install bug-fix-red-green --dest ./loops; bl run ... --yes --run-id first-proof; wreck.sh demonstration. (https://github.com/qualixar/bounded-loops#readme)
- Quick start executed on 24 Nov 2026 in a clean virtualenv with bounded-loops 0.7.7 (PyPI): "[DONE] gate-passed (laps: 1)" and "Gate verified: the independent acceptance gate passed after 1 lap." (https://pypi.org/project/bounded-loops/)
- The wheel ships 69 loops (65 keyless); the repository adds seven digest-pinned graphs. (https://github.com/qualixar/bounded-loops#readme)
- bl graph run --execute needs macOS (Seatbelt isolation); every other command runs anywhere. (https://github.com/qualixar/bounded-loops#readme)
- Paper: a bounded loop is a worker, an independent gate the worker cannot write to, and a declared budget; durable-execution platforms bound retries and time but the checker usually lives in the same codebase as the work. (https://arxiv.org/abs/2609.27871)
- Paper: 47 vacuous gates found in a 69-loop catalogue; no false accepts over 209 destroying mutants is saturation, not quality; a fresh operator family on frozen gates recovered a 23.3% false-accept rate. The paper evaluates v0.6.6. (https://arxiv.org/abs/2609.27871)
- Licensed under Apache-2.0 (LICENSE file). (https://github.com/qualixar/bounded-loops/blob/main/LICENSE)
- 5 GitHub stars for qualixar/bounded-loops on 24 Nov 2026. (https://api.github.com/repos/qualixar/bounded-loops)
- Ralph: runs Amp or Claude Code repeatedly until all PRD items are complete; fresh instance each iteration; 22,337 stars; MIT. (https://github.com/snarktank/ralph#readme)
- LangGraph: low-level orchestration framework for stateful agents; durable execution; human-in-the-loop; 45,352 stars; MIT. (https://github.com/langchain-ai/langgraph#readme)
- Four of the 69 shipped loops require a framework package (langgraph, crewai, agent-framework or google-adk). (https://github.com/qualixar/bounded-loops#readme)
