# Level 5: You Run the Software Factory

URL: https://developertoolkit.ai/en/ladder/level-5-run-the-factory/
Description: Level 5 of the autonomy ladder: the six Software Factory stations across Claude Code, Codex, and Cursor, plus the four-question autonomy ledger.

Level 5 of the autonomy ladder is the software factory: a six-station pipeline (**Intent · Harness · Loop · Graph · Verification · Release**) where agents pull work from a queue, build and verify changes, and open pull requests without human-written code. A loop earns unattended factory operation only when an independent oracle outside the agent's reach decides done.

Your [Level 4](/en/ladder/level-4-write-specs/) runs already complete overnight, review latency has become the slowest leg of delivery, and leadership asks whether routine changes like dependency bumps can run continuously from a queue. This guide equips tech leads, platform engineers, and CTOs to decide which loops qualify, build the first loop safely, and map all six stations across Claude Code, Codex, and Cursor.

## How close production teams actually are to a dark factory

Dan Shapiro (*The Five Levels*, 23 January 2026) describes Level 5 as *"a black box that turns specs into software"* and places only a handful of tiny teams there (Simon Willison's February 2026 write-up highlights StrongDM's AI division using external holdout scenarios).

The best-documented scaled production factory—Stripe's Minions—keeps humans in the merge loop. Stripe reported **over 1,300 merged pull requests per week** containing zero human-written code (19 February 2026), operating against **over three million pre-existing tests** and strictly capped at **two rounds of CI** before escalating to a human (9 February 2026). The verification layer existed years before the agents.

Skipping that layer carries steep production penalties: Faros AI's telemetry across 22,000 developers (April 2026) measured task throughput rising 33.7% while incidents per pull request surged 242.7%, median review time jumped 441.5%, and unreviewed merges climbed 31.3%. Treat Level 5 strictly as a property of individual high-oracle loops.

## The six stations of a software factory

Each station owns one explicit decision and emits auditable evidence:

| Station | Decision owned | Mandatory evidence | Failure when missing |
| --- | --- | --- | --- |
| **Intent** | What the agent knows before starting | Versioned spec, acceptance criteria, stop condition | Plausible code solving the wrong problem |
| **Harness** | What the agent may run and access | Versioned sandbox, hooks, and least-privilege policy | Runs succeed only because permissions are overly broad |
| **Loop** | When execution halts | Machine-checkable stop condition and hard retry bound | Infinite thrashing or premature verbal victory |
| **Graph** | Who does what across agents | Written topology (planner, workers, judge) + worktree isolation | Concurrent agents overwriting files or shared state |
| **Verification** | What proves correctness | Independent deterministic checks + advisory review findings | Green builds on tests rewritten by the agent |
| **Release** | How changes ship and roll back | PR evidence bundle, named merger, canary/auto-rollback | Merges nobody can audit or revert cleanly |

Audit all six stations locally in any repository with `npx @wondelai/harness-audit` ([harness audit guide](/en/workflows/harness/harness-audit-guide/)). Deep factory design lives in [software factories](/en/method/principles/software-factories/).

## The four-question autonomy ledger: which loops may run unattended

A loop must cleanly pass all four tests before leaving live supervision:

1. **Named oracle:** does an exact command exiting 0 decide done?
2. **Oracle independence:** is that oracle impossible for the agent to weaken in the same diff?
3. **Fast feedback:** does a wrong change surface in minutes rather than weeks?
4. **Contained blast radius:** is a mistake small and reversible by a single revert?

| Loop class | Oracle | Agent-editable? | Time to surface | Blast radius | Verdict |
| --- | --- | --- | --- | --- | --- |
| Patch/minor dependency updates | Full CI + contract suite | No (tests & CI locked) | Minutes | Single revertable PR | **Factory loop (evidence merge)** |
| Lint rules & typed codemods | Linter + type checker | No (configs locked) | Minutes | Mechanical, reversible | **Factory loop (evidence merge)** |
| Flaky-test quarantine | CI re-run telemetry | Yes if inside repo | Days | Masks real regressions | Supervised |
| Feature work from a spec | Spec acceptance tests | Yes if in same diff | Days–weeks | Product behavior | Supervised L4 evidence review |
| Auth, money, schemas, migrations | Partial at best | Varies | Weeks | Irreversible | **Always human code review** |

## Standing up your first factory loop in six steps

Start with patch and minor dependency updates because its deterministic oracle already exists:

1. **Commit the intent file** (e.g., `.factory/dep-bump.md`) under version control so prompt changes undergo standard code review.
2. **Move the oracle out of reach.** Protect `tests/`, `.github/`, lint configs, and type configs via `CODEOWNERS` with required code-owner reviews, pin required workflows to the default branch, and fail any factory branch touching protected paths ([protecting the oracle](/en/workflows/test/protect-the-oracle/)).
3. **Split execution from publishing.** Run the agent inside a disposable sandbox with zero write credentials (`persist-credentials: false`, only the model key). Export changes as a patch artifact; a separate, non-agent job with narrowly scoped GitHub permissions applies the patch and opens the pull request.
4. **Run headless with hard bounds.** Enforce least-privilege tool allowlists, spend limits, and at most two automated fix rounds (mirroring Stripe's two-round CI cap).
5. **Merge from an [evidence bundle](/en/workflows/ship/evidence-bundle/).** Include the intent reference, exact command exit codes, automated review findings, and dependency changelog.
6. **Hold steady for four weeks.** Track revert rate, incidents per PR, and review wait before onboarding a second loop class.

**Audit prompt: write the verification contract for one factory station**

```text
Station: Verification. Loop: patch and minor dependency updates.
Do not modify any files. Output a markdown table specifying:
1) accepted inputs; 2) deterministic validators exiting 0 before hand-off;
3) whether the agent can edit any validator (and how to move editable ones outside the diff);
4) failure routing and max retry count; 5) human escalation trigger.
Close with the four-question autonomy ledger verdict: factory-ready or keep supervised.
```

## Mapping the six stations across Claude Code, Codex, and Cursor

Exact CLI flags, cloud triggers, and enterprise billing evolve quickly—check vendor documentation on the day you wire a pipeline ([Claude Code docs](https://code.claude.com/docs), [OpenAI Codex docs](https://developers.openai.com/codex), [Cursor docs](https://cursor.com/docs)):

| Station | Claude Code | Codex | Cursor |
| --- | --- | --- | --- |
| **Intent** | `CLAUDE.md` / `AGENTS.md`, Agent Skills (`SKILL.md`), Plan mode | `AGENTS.md` hierarchy, Agent Skills, Plan mode | `.cursor/rules/*.mdc`, `AGENTS.md`, Agent Skills, Plan Mode |
| **Harness** | Lifecycle hooks (`PreToolUse`, `PostToolUse`, `Stop`), managed hooks, OS sandbox, least-privilege allowlists | `sandbox_mode` (`read-only`, `workspace-write`, `danger-full-access`) vs `approval_policy` (`on-request`, `never`, `granular`; legacy `untrusted` retired), `requirements.toml` | Hooks, run modes, isolated Cloud Agent VMs, enterprise admin policies |
| **Loop** | Headless runs, goal loops, `Stop` hooks (`stop_hook_active`), scheduled routines | Non-interactive execution, cloud environments, scheduled automations | Cloud/Background Agents, scheduled & event-driven Automations |
| **Graph** | Subagents (`.claude/agents/`), git worktrees, script-driven orchestration | Subagents, managed git worktrees, cloud tasks | Subagents, isolated worktrees, Agents Window |
| **Verification** | Automated code review (`REVIEW.md`, `/code-review`), security review | Codex code review (`AGENTS.md` review rules), security review | Bugbot (`.cursor/BUGBOT.md`), security review |
| **Release** | CI/CD actions & headless integrations | CI action & GitHub/GitLab PR review | GitHub Actions, webhooks, PR routing & approval |

Never place broad permission-bypass flags in any factory loop outside a disposable, network-restricted container; a loop requiring unrestricted access exposes a broken harness.

## Proving factory quality without reading every diff

- **Deterministic checks decide; review agents advise.** Types, tests, linters, and migration checks gate merges; AI reviewers surface findings rather than acting as sole gates.
- **Weekly random sampling audit.** One named loop owner inspects a small random sample of merged factory PRs end to end every week. Any defect missed by gates returns the loop to supervised mode until a new check covers the gap.
- **Four loop-level metrics:** revert rate, incidents per PR, review wait, and share merged without human approval.

## Where a software factory rots first, and how to recover

- **Factory output outruns human review.** Review queues swell while throughput looks healthy (the Faros pattern). Recovery: cap open factory PRs per loop, pause intake at the cap, and review evidence bundles instead of raw diffs.
- **The oracle drifts into agent write reach.** Green runs quietly modify tests or lint configs. Recovery: revert, enforce `CODEOWNERS` on test and CI paths, and add a fail-closed CI path check.
- **Unattended jobs inherit yesterday's permissions.** Stale allowlists run at 3 a.m. Recovery: version every permission policy in code review, enforce org limits via managed settings or `requirements.toml`, and audit quarterly.
- **Untrusted external text reaches tool-enabled agents.** Issue descriptions, external PR comments, webhooks, and scraped HTML are prompt-injection vectors. Recovery: isolate untrusted parsing inside read-only, zero-secret steps and hand write steps to separate constrained jobs ([agent threat model](/en/org/agent-threat-model/)).
- **Nobody owns the seams across stations.** Six owners with no end-to-end accountable lead ship green broken software. Recovery: assign one named loop owner empowered to pause automation without a committee.

## Next steps

- [Software factories](/en/method/principles/software-factories/) — Full architectural guide and autonomy ledger design
- [Issue-to-PR pipeline](/en/workflows/automate/issue-to-pr-pipeline/) — Worked end-to-end automated loop across tools
- [Background agents](/en/workflows/automate/background-agents/) — Governance and isolation patterns for scheduled unattended runs
- [The human's job](/en/ladder/the-humans-job/) — Six decisions no factory station can automate
