Fix a failing CI build
Let an agent fix code and retry until your test command passes.
What this example covers
Section titled “What this example covers”- Sandbox sessionsOne warm sandbox keeps dependencies between agent turns and test runs.
- Repository and branchThe fix lands on a named branch, never on your checkout.
- Prepare the environmentDependencies are installed once, before the first round.
- Verification loopsAttempt, check, feed the failure back, repeat.
- BudgetsCap the attempts and tokens of the whole run.
- Run in CIA failed run throws, so the job exits non-zero.
Write the script
Section titled “Write the script”Save the files shown in the tabs next to the configuration from Installation. The entry script keeps one sandbox open so the agent’s edits and your test command use the same files.
Keep sandbox allocation, the agent attempt and commit checks in separate files.
Compose the loop and run fix-ci.ts, which owns and closes the sandbox.
Run the script
Section titled “Run the script”Run the verification loop, then inspect the commits on its branch. The script prints the status, the number of rounds and token usage, and exits with an error if the workflow fails.
Understand the steps
Section titled “Understand the steps”perform(context) ties the agent’s usage and cancellation to the workflow, so its tokens count against budget. timeoutMs bounds each round.
| Outcome | result.status | result.errors | Exit code |
|---|---|---|---|
| A check accepts the round | "done" | Empty | 0 |
| The fourth check rejects | "failed" | LoopTaskExhausted, with feedback | 1 |
| Tokens or attempts run out | "failed" | WorkflowBudgetExceeded | 1 |
| The agent or a command throws | "failed" | The thrown error | 1 |
result.unwrap() throws a WorkflowFailure for every row but the first. A token limit also stops the agent that is running.
Adapt the example
Section titled “Adapt the example”| Variation | Change |
|---|---|
| Another agent | Pass a fallback agent as agent: createFallbackAgent([claude, codex], { on: ["quota", "unavailable"] }) switches on a usage limit or an outage. |
| Run it in CI | Use an unattended credential, name the branch per run (`outpost/fix-ci-${process.env.GITHUB_RUN_ID}`), then git push origin that branch. |
| Stricter check | Add npm run lint or a typecheck after the tests, or ask a reviewer agent from check (Verification loops). |
| Cloud sandbox | Replace sandboxProvider with a Vercel or Daytona provider. Commits come back to the branch on the host. |
API: createSandbox · defineLoopTask · defineAgentTask · WorkflowBudget · LoopTaskExhausted · WorkflowFailure.