# A jail, a factory and an orchestrator for AI coding agents

Nov 29, 2026 · 16 min read · João Ramires

Before the jail, the sandbox I built for my coding agents, held a single agent, I set reviewer agents on its plan and told them to break it. The first one found the worst hole. An agent could land a branch with a file named `config/initializers/zz_pwn.rb`, then ask the broker, the small service that runs privileged actions for the jail, to migrate the database. The broker would run `bin/rails db:migrate` as me, and my user can do almost anything on that machine. The agent’s own file would run with my rights.

The fix is a rule: no broker action runs project code as me. With the fix removed, 12 of its 16 tests fail, which is how I know the tests mean something. That moment shaped everything after it. I let AI agents write most of the code on my machine, and I don’t trust them with it. Both are true at once, and the framework in this article is how I live with that.

It has no name. In the first note about it I wrote that I was trying to create a framework to power my agentic software development factory, “if I had to give it a name”. I never gave it one. It has four parts. A jail that holds every agent. A factory that moves work through a queue and a set of gates. An orchestrator, my main Claude Code session, that plans the work, briefs the builders, reads their results and merges. And a planning app, [Consilium](https://joaoramires.xyz/writing/consilium/index.md), where my words, the queue and the lessons live. This article covers the first three, and each through the faults that made me build it, because faults tell the design more honestly than a diagram does.

## What I wanted

I wrote down five goals early:

- Almost no agent blocked waiting for me.
- Software built with correctness, quality, security and documentation.
- An orchestrator that can decide things for me when I want it to.
- Agents that can’t hurt each other’s work, or mine, even if they try, on a shared machine.
- A [CI](https://en.wikipedia.org/wiki/Continuous_integration) I can trust, so we merge with confidence.

The first goal wants agents free. The fourth wants them caged. The framework is where those two meet. My rule of thumb: ask me only for real money, secrets, `sudo` and logins. Everything else should get through on its own, or be stopped by software, and not by me typing “yes” all day.

## The shape of it

One change travels this way.

```mermaid
flowchart LR
  O[Orchestrator] -->|brief| Q[(Work queue)]
  Q --> B[Jailed builder]
  B -->|branch| G{Fetch gate}
  G -->|held for me if a protected path changed| R[Jailed reviewer]
  R -->|PASS| M[Merge gate]
  M --> D[main]
```

*One change, start to merge*

The orchestrator never touches the builder’s files. It writes a brief and puts the work in the queue. A builder runs inside the jail, on a throwaway clone, and pushes a branch to a small exchange, the outbox. The branch comes back to my side through a gate that checks it, and the gate holds anything dangerous until I confirm at a terminal. A reviewer, also jailed, reads the result. Only then do the merge checks run: the project’s tests on the merged tree, once in a fresh jail for the jail’s proof and once on the host for the factory’s merge tool, which lands the change. Nothing in that line trusts the step before it.

## Part one: the jail

I call the sandbox “the jail”. It lives in its own repository. The promise is simple to say: an agent can’t do harm, even if it tries. Picture an agent that obeys a hostile line hidden in a web page, or that is just wrong. It might reach for the system, my data and processes, my credentials, other sessions, or the machine’s memory and disk. The design has ten layers, built to fail one at a time without the whole thing falling.

### The box comes from Fabio Akita

The box each session runs in is not mine. It is [ai-jail](https://github.com/akitaonrails/ai-jail), an open-source tool by [Fabio Akita](https://www.akitaonrails.com), written in Rust. On Linux it puts a coding agent inside bubblewrap, with Landlock and seccomp filters, so the agent sees its project and very little else. It was the right base, and my jail would have taken weeks longer without it. Thank you, Akita.

Akita is clear about what ai-jail is: a guard against the mistakes of an agent you trust, not a wall against an attacker. For hostile code he points to a disposable VM. I took him at his word, so in my jail ai-jail is one layer of ten. The other nine, and the hardening of ai-jail’s own setup, are what I built around it.

### The ten layers, and who built each

| # | Layer | What it stops | Built by |
| --- | --- | --- | --- |
| 1 | A separate Unix user, `agent` | Reading my files, touching my processes, `sudo` | Me |
| 2 | A session scope, a memory and CPU slice, a capacity check | A runaway session, or too many at once, starving my desktop | Me |
| 3 | A disk quota, and a seccomp filter of my own | A full disk, and a file-system trick that escapes the quota | Me |
| 4 | Firewall rules for the agent user | Reaching my home network, my local services, anything but the web | Me |
| 5 | ai-jail: bubblewrap, Landlock and seccomp | Seeing anything outside the project’s clone | Fabio Akita (I harden its setup) |
| 6 | A credential proxy | The model token ever entering the jail | Me |
| 7 | Throwaway clones, an outbox and a broker | Agent code running on my side; work leaving the jail except as a branch I fetch | Me |
| 8 | A project registry with protected paths | A project widening its own jail, or a branch changing what guards the system | Me |
| 9 | A separate user for live services, with hardened units | A merged change harming live data or secrets | Me |
| 10 | Audits, session records, backups and an escape suite | A guard that decays without anyone noticing | Me |

Beyond the layers, I harden ai-jail itself. Its global config belongs to root and can’t change. Sessions inherit no environment, no project config, no GPU and no Docker, and one module builds every jail command line, so no other file can add a flag. I build ai-jail from a pinned, signature-checked source, as a locked system user with no home and no shell, because building Rust code runs other people’s build scripts and this way they can touch only their own folder. New commits get a secret scan before they reach the jail’s inbox, and an agent’s branch gets one before it lands. Each session gets a throwaway Postgres and warm build caches, so a jailed build is not slower than my own shell.

Four of the layers show the character of the whole.

**A separate Unix user.** Agents run as a user called `agent`, and the kernel refuses it my files and my processes. It is the oldest and most boring layer, and it holds when everything above it breaks. It has no `sudo`, no `docker` group and a locked password. Reviewers still found holes around it. My cleanup script decided the agent was idle by looking at process names, and a process can pick its own name. The final version waits until the kernel reports zero processes owned by that user. Process names are claims, and only the kernel’s user ids count.

**Limits.** The agent slice may use 70% of memory softly, 80% hard, and 75% of the CPU, and a disk quota caps disk use. A new session waits in a queue when the machine has no room, so it never starts and starves my desktop. I measured these numbers on a full CI run of my trading system: a median of 577.5 seconds over three runs, with a spread of 4.8%. The memory counter of the cgroup said the build used every byte it was allowed, in all three runs. The real working set was under a quarter of that, because the counter included the file cache, which the kernel gives back at once. I sized the limits from the working set, and not from the counter.

**An escape test suite.** A script tries to break out of every guard, with canaries, after each upgrade and every week. The rule of the repository: a change to a guard ships with a change to the escape test that proves it. The manifest has 37 attack rows. The last run I counted, on 2026-11-29, covered 36 of them: 28 passed, 7 were skipped and 1 failed. I don’t claim every escape is shut. I claim that I look every week, and that a failing row is written down.

**The credential proxy.** A coding agent needs an account to think with, and an account is a secret. For a while the token sat inside the jail. Now the jail holds only the word `placeholder`, and a proxy outside it adds the real token. The proxy serves only sessions that hold a lease, and it limits the calls, the models and the length of answers. Reviewers attacked it, and every attack got a fix. The pattern repeated: the proxy trusted a number that a process could change, and the fix tied the check to something the kernel vouches for. I’ll be honest about what it does not do. A jail can still use my account inside those limits, and put data in prompts. I accepted that and wrote it down as an open risk.

### What the reviews found

The part I trust least is the part nobody tried to break, so I set reviewer agents to attack the sandbox. It went through a plan review, two deep reviews and a long series of re-checks. Besides the broker hole above, the second review found a race. A check passed, and then the thing it checked changed before it was used: after the outbox check, the reviewer added an `alternates` file, and the next fetch served objects through it. The fix stops reading the shared copy at all and works from a private one.

The later rounds found the same kind of gap again and again, in the proxy and in the audit of the runtime units. The fixes moved from “block this case” to “change the rule”, from deny lists to allow lists. Blocking one case invites the next, and changing the rule ends it.

## The gate between the jail and me

The jail has one door, and it is the part I use most. When a builder finishes, the orchestrator runs `fetch-branch`. It brings the branch home with hooks off and path checks on. If a protected path changed, the fetch is held, with exit status 3. Protected paths are the ones that can run code as me, reach a secret or instruct the next agent.

To release a held branch I type a confirm code from a desktop notification, which shows the commit, at a terminal. A jailed process can’t do that, and an approval from the orchestrator can’t stand in for it.

I relaxed this gate once, when it got in the way. The confirm screen used to refuse a branch of more than 400 paths and say “split the branch”. A batch of 8 to 10 branches has 400 to 600 paths, so each batch cost a rework, and I said I would rather scroll than slow down. Now the screen prints every path with a totals line. The checks that protect the machine stayed, and only the human-facing limit went.

After the confirm comes the merge proof. The sandbox computes the merged tree from my repository and runs the project’s proof script in a fresh jailed session with no secrets. It writes the proof only when the run ended with 0, and the command that lands the change reads that file. A ref in the outbox is never a proof. That is the jail’s own check. The factory’s merge tool, in the factory section below, runs the tests once more on the host.

## Part two: the factory

The jail knows nothing about work. It holds agents. The factory knows what a piece of work is.

It began as scattered scripts inside my trading system: a queue, a board, a guard, approval tools and a merge tool. On 2026-10-10 I wrote the rule that decided the architecture: the two projects shouldn’t be coupled. I can run and develop the trading system without the jail, and I can use the jail to build other software. So the repositories point one way.

```mermaid
flowchart TD
  F[agent-factory] -->|command interface| S[agent-sandbox]
  P[Products] -.->|profile only| F
  S -. knows nothing of .-> F
```

*Three repositories, one direction*

The factory uses the jail through its command line, and the jail knows nothing of the factory. A product depends on neither. It supplies a profile that says what it needs, such as its build and test commands, its protected paths and its merge tool. That is why the factory code contains no project name. My trading system was the first project to use the jail, and a small command-center app, Beholder, is the second one with a factory profile. That was my test of the decoupling. The factory is plain Ruby, no Rails: glue around git, files and processes.

The protocol that moves one piece of work is called Gatepost. I designed it with an agent and I own it. The unit of work is one change written with [OpenSpec](https://github.com/Fission-AI/OpenSpec), an open-source tool for writing specs next to the code, and it has six states: planning, building, review, merging, done, dropped. “Waiting” is a condition shown next to a state and never a state of its own, because a wait can happen anywhere. My first draft had ten states, and a reviewer argued that most of them were waits. It was right. Every fact goes into one append-only log per project, written only by the software, so status, the merge gate and my dashboard read the same file and can’t disagree.

Approvals are empty git commits, “Plan approval of X” and “Result approval of X”, carrying my words, or the delegation that covers them. A batch of changes gets one deep review by a jailed reviewer, and its verdict is PASS or BLOCK. Then the merge tool runs the project tests on the result, on the host, in a temporary worktree with no shell and no hooks, and refuses unless they pass.

The gates say no often, which is what I built them for. As of 2026-11-29 the factory log holds 868 runs since 2026-10-20. Of 294 builds, 32 ended blocked. Of 82 merge runs, 39 failed. Each of those failures stopped at a gate and never reached main.

### What the factory taught me about itself

The faults that shaped the factory were mostly in the seams.

**The archiver erased the work.** A change added three capabilities, and the merge gate wanted a design with a “…in one picture” section for each. A builder wrote them and the check passed. Then the archive step, a fresh agent with a one-line brief, wrote two-line stubs over the three files, and the merge was refused again. The fix was no smarter agent. I put a note inside the change itself (“keep these three files; run the check before you commit”), because the archiver reads the change. A fresh agent knows only its brief and the files, so the rule goes where it will look.

**A green check that checked nothing.** A verifier agent wrote “clean” for a page change after it read only the code. Its report was honest and listed every browser check under “Not verified”. But every gate read only the severity lines, and a report with no finding passes. A review that does nothing looks the same as a review that finds nothing. Now the gates ask for proof of the work, such as screenshots and test result lines, and not only for the absence of findings.

**Two programs, one contract, no test.** The factory passed its whole test suite and a long list of planted faults, and still couldn’t approve its first real batch. Three faults sat where it met the trading tool: one command line for every kind of call, a member call for an item with no change folder, and a tool that printed two files on one line while the factory read one path per line. Each side’s tests passed. A fake in a test copies what its author believes about the real tool. Now every join gets a host task that runs the real tool on the other side before first use.

**The work was fine, the machine was wrong.** A good batch passed its review and my approval. Then the archive step failed because the jail’s gem cache was stale. Rebuilding the cache was quick, but the run ended `blocked`, and the retry accepted only `failed` or `lost`, never a batch that held an approval. I had to drop the batch and approve it all again. A workflow engine must tell “the work is wrong” from “the machine is wrong”. Now `factory retry` repeats a run that failed for a reason outside the code, and it refuses, with a named reason, after a gate said no.

## Part three: the orchestrator

The orchestrator is my main Claude Code session. It has no special software of its own. It has rules, and the rules are most of the setup. Hooks put the queue, my standing rules and a reminder to record my words into every turn.

The first rule is that it writes documents and not code. I told it I don’t want it writing code itself, while plans, briefs, reviews and notes are fine. A builder, a cheaper model with its own agent file, writes code and tests. A hook refuses edits outside the orchestrator’s scratch and notes folders, and the refusal is final.

The second rule is that every subagent runs in the jail. No agent starts on the host. A builder’s result is untrusted text, so the orchestrator checks each fact, fetches through the gate and reads the diff. A hook refuses approvals and merges from any subagent. Approvals, merges and restarts stay on the host.

The third rule is that a brief is a complete document. It names the goal, the files, the decisions, the constraints, the check for each task and the shape of the report, and it starts with one fixed line that names the worktree and the change, so the queue can tie a run to its work. I learned why it must be complete when a continuation brief said “read the first brief” and gave a host path. The jail has no such path, so the builder checked step 1 without its goal and wrote `NOT VERIFIED`. A brief for a jailed agent can’t point outside the jail.

The fourth rule is delegation. Most of the day I am not in the loop. The orchestrator approves plans and results for me and records each as a pick, a choice with its options and reason, which [Consilium](https://joaoramires.xyz/writing/consilium/index.md) keeps. It asks me only for what is finished and ready. One day it asked me for a plan decision instead of fixing the tool that blocked it, and I told it that delegation mode exists so it is not blocked. It then treated the block as a gap in the tool, recorded it and planned the fix, which is what I want.

### Where the orchestrator itself failed

The orchestrator fails too, and I keep those lessons next to the jail’s, because the cage has to hold for the agent at my side as well.

**It chained a fetch and a fast-forward.** The fetch printed `HELD`. The fast-forward ran anyway, since both sat in one command, and a review started on a branch I had not confirmed. It was caught, and I was asked to confirm. The next day it did the same thing again. A rule that depends on remembering will be forgotten, so the rule is now narrow and mechanical: run the fetch alone, read it, and go on only if it says no protected path changed. A hook also refuses a `kill` whose process number came from a search in the same command.

**It said a rule was recorded when it was not.** I had told it four times that one tool must not couple to a spec format. It copied my words into notes and design files and recorded no decision. Three days later a build broke the rule and the orchestrator approved it. An audit of the transcripts found 33 more standing rules of mine that were recorded nowhere. Now each standing rule becomes a decision at once, with my exact words, and every plan approval first reads the rules of the project. That is the kind of miss Consilium exists to stop, and [its article](https://joaoramires.xyz/writing/consilium/index.md) tells that story.

## What is still open

I keep a list of what the jail doesn’t promise, and I’d rather publish it than hide it. It does not stop a flaw in the kernel or in ai-jail. It does not stop data leaving through an allowed host, because the proxy can’t read inside [TLS](https://en.wikipedia.org/wiki/Transport_Layer_Security). It does not stop a bad instruction from reaching an agent, only what the agent can do after. And an agent can still write bad code and ask to merge it. That is what review is for, and review is a judgment, not a wall.

One more honest number. As of 2026-11-29, 38 outcomes in my tracker wait for me to confirm them, some for 16 days. The framework takes me out of the hot path, and it doesn’t make me faster at the rest.

## What I’d tell someone building the same

- Keep the cage dull. A separate user, a firewall rule and a quota do most of the work, and they are easy to explain. The clever layers are the ones that need many review rounds.
- Build on good open work, and say whose it is. Fabio Akita wrote the box, and ai-jail gave me a sound base for nine more layers.
- Bring in attackers, even if they are agents. A review found the critical hole in my broker design, and the builders’ own tests never did.
- Make every gate prove that it refuses and that it accepts. A gate that refuses your own project is as broken as one that lets the attack in.
- Put each rule where the next agent will read it, and let a hook catch the rest. A rule that lives in a chat, or in the head of the orchestrator, is lost.
- Keep the parts apart. The jail holds agents, the factory moves work, and the products do their jobs. When they don’t know about each other, I can change one without asking the others.

The factory has more to tell than fits here, and it gets [its own article](https://joaoramires.xyz/writing/software-factory/index.md) in my series on [applied AI engineering](https://en.wikipedia.org/wiki/Artificial_intelligence_engineering).
