From incident to fix PR with an RCA agent
Connect a Claude Code agent, let it triage an incident in a sandbox, read what it found, and follow its proposed code fix from approval to a pull request that only you can merge.
When a release fails in production, the first hour is usually spent working out what changed. This tutorial hands that hour to an agent, and keeps every decision with you. A Claude Code agent reads the incident in a sandbox and reports its likely cause. When it proposes a fix, you read the exact diff, approve it, and Wardn pushes a branch and opens a pull request with its own GitHub App credential. The agent never holds a write token and nothing is merged for you.
It takes about 40 minutes and ends with:
- an agent that triages Sev 2 incidents, running in a sandbox with a deny-by-default network;
- an incident whose page shows the likely cause, the evidence and the agent's work;
- a pull request opened by Wardn from an
agent/…branch, with the proposal, the approval and the execution in Activity; - the kill switch, tried once so you know it works before you need it.
Which parts exist in your version
Parts 1 to 3 (the agent, the sandbox, triage and the likely cause) are available with agent jobs. Parts 4 and 5 (the proposed fix and the pull request) need remediations. A triage job is read-only, so the fix comes from a root-cause (RCA) job, which may propose when your version has remediations. If your version has no propose_remediation, stop after Part 3: you still have triage and the likely cause.
You need the deployment from Deploy your first app in a production environment (so a failure there is Sev 2), connected to a GitHub repository through the GitHub App with write access to contents and pull requests, an Anthropic API key, and Docker on the machine that runs the Wardn worker. You need to be the Owner, or to hold agent:manage, incident:read and remediation:approve. For the API tabs set WARDN_API_URL and WARDN_TOKEN and define:
api() { curl -fsS -H "Authorization: Bearer $WARDN_TOKEN" -H 'Content-Type: application/json' "$@"; }Part 1: turn the sandbox on
An agent's work runs in a box that Wardn makes and removes. Without one, Wardn starts no job.
Choose a provider
For a try-out use Docker. For production use OpenShell. Set these on the worker and restart it:
WARDN_SANDBOX_PROVIDER=docker
WARDN_MCP_URL=https://wardn.example.com/mcp
WARDN_SANDBOX_DOCKER_SHIM=/opt/wardn/sandbox-shim
WARDN_SANDBOX_DOCKER_STATE_DIR=/var/lib/wardn/sandboxWARDN_MCP_URL is the address a box reaches Wardn at, and the only host it may reach besides the model. The variables are listed in Configuration.
Part 2: connect the agent
Create it with Claude Code as its runtime
Make an agent called triage, runtime Claude Code, owned by the team that owns the deployment. Give it only read roles on that team's deployments. A triage agent has no use for a role that writes, and a job could not use one anyway.
AGENT_ID=$(api -X POST "$WARDN_API_URL/api/v1/agents" \
-d '{"name":"triage","runtime":"claude_code","placement":"local","maxAutonomy":"recommend","teamId":"'"$TEAM_ID"'"}' | jq -r .id)Point its model key at a secret
Put your Anthropic key in the secret store under a name such as agents/triage/model-key, then give the agent the name. Only the name goes through the API.
api -X PUT "$WARDN_API_URL/api/v1/agents/$AGENT_ID/credentials/model_key" -d '{"ref":"agents/triage/model-key"}'The key reaches the model at the sandbox boundary. The agent holds a placeholder, so a prompt that makes it print its environment shows nothing usable.
Make it the triage agent for Sev 2
api -X PUT "$WARDN_API_URL/api/v1/incident-triage-rules/2" -d '{"agentId":"'"$AGENT_ID"'"}'Add Sev 1 too if you want. A severity with no rule is not triaged.
Part 3: cause an incident and read what the agent found
Ship a change that fails its checks
Add a failing health rule to the production deployment's app, or push a commit that makes its Deployment unready, and release it. The wave fails and Wardn opens R-… wave 1 failed its checks as a Sev 2 incident, because the deployment is in production. See When Wardn raises one itself.
Watch the job
Open the incident. Agent work shows a triage job, J-…, queued, then running while its box is up, then succeeded. While it runs the agent makes ordinary calls with its own roles: reads the app, lists deployments, reads logs and the deployment's timeline. Audit › Activity shows them as the agent's.
INC=INC-12
api "$WARDN_API_URL/api/v1/incidents/$INC" | jq '{agentJobs, likelyCause}'A job that fails says why (timed_out, no_result, sandbox_failed…). The list of reasons says what each means.
Ask for a root cause by hand
Triage runs by itself, and only reads. To ask the same agent for a root cause, or to run it again after a change, start an RCA job. It is the same call as Re-run:
api -X POST "$WARDN_API_URL/api/v1/agent-jobs" \
-d '{"agentId":"'"$AGENT_ID"'","kind":"rca","subject":{"kind":"incident","id":"'"$INC"'"}}'It is refused if the agent's own roles cannot read the incident, so a missing read role shows up here, not as a job that fails. Cancel one that is running with POST /agent-jobs/{jobId}/cancel. A finished RCA takes over the incident's Likely cause from triage.
Read the likely cause, then check it
The incident now has a Likely cause: the agent's conclusion, how sure it was and links to what it relied on. It is a claim, not a fact. Open the evidence and see whether it holds: the release, the snapshot compare, the log line. A low confidence is the agent telling you to look yourself.
Part 4: the proposed fix
Needs remediations
Do this part only if your version has remediations.
See the proposal
When an agent allowed to propose finds a fix in code, it calls propose_remediation with the kind code_fix: the changed files, a branch name under agent/ and a title. The incident's Fixes list shows it as RM-… and pending. Open it: the diff is what Wardn computed from the real files at the head of the base branch, not what the agent says they hold.
api "$WARDN_API_URL/api/v1/remediations?status=pending" | jq '.items[] | {id, ref, title, type, status}'Approve it
On the proposal, read the diff, then choose Approve. Decline and Request changes need a note, and a decline counts against the agent's track record.
You cannot approve a proposal you asked for, and no agent can approve at all. Approving twice, or two people at once, approves it once.
Check the pull request
The proposal moves to executing, then executed, with the branch, the commit and the pull request's address on it. Open the pull request: it is on the repository's agent/… branch, opened by the GitHub App and not by the agent, and it says who proposed the change and who approved it. Wardn has no way to merge it, push anywhere outside agent/…, force-push or delete. You review and merge it as you would any pull request, or close it.
If the base branch moved after the proposal, nothing is pushed and the proposal ends expired; ask for a new one.
Read the record
Audit › Activity holds three entries: the agent proposed it, you approved it, and Wardn executed it under the approval of you, proposed by the agent. Who proposed, who approved and who made the change are three separate facts.
Part 5: stop every agent
Try the kill switch once, on a quiet day, so you know where it is.
api -X PUT "$WARDN_API_URL/api/v1/agent-kill-switch" -d '{"paused":true,"reason":"tutorial"}'Every agent's next call is refused on every replica within seconds, a job that is running stops and its box is removed, and no new job starts. Resume with {"paused":false}; agents that were paused on their own stay paused. See Pausing everyone.
What you built
An agent that reads an incident under the roles you gave it, in a box that can reach only Wardn and its model, holding no credential it could leak. A person who read a diff before anything touched a repository. A pull request that Wardn opened and only your own review can merge. And a switch that stops all of it.
Protect production
Put guardrails on a production environment, hold its deploys every Friday afternoon with a recurring freeze, excuse one deployment with an exception that has a review date, and see what a blocked deploy looks like.
Helm with values per environment
Keep one Helm chart in git and give staging and production their own replicas, resources and image tag as values on the deployments.