Topic 5 of 5 · 5 min read
Containing an incident an agent caused
Goal: Order the containment steps after an agent ran a destructive command in production: stop, revoke, preserve evidence, restore.
When an agent has run a destructive command in production, contain in this order: stop it, cut its access, save the evidence, then restore. Each step protects the next one.
Check yourself · 1 of 3
An agent just ran a destructive command in production and is still running. What comes first?
Why it matters
Agents run commands fast and keep going until told to stop. A coding agent with production credentials that misreads a task can drop a table, delete a bucket, or force-push over history in seconds, then continue with a "fix" that makes it worse. Its logs may also be overwritten or lost when the session ends. A calm, fixed order prevents the second mistake.
The order
- Stop the agent. Interrupt the session, kill its process or pause the job. Use the exact process or job ID you know is the agent's; on a shared machine, never kill by name. Do not let it "repair" anything.
- Revoke and rotate its access. Disable the API key, token or role the agent used. If it could have seen other secrets, rotate those too. This stops any further damage, including from a second session using the same credentials.
- Preserve evidence. Before restoring, copy the agent's transcript, the command history, the audit log and the database logs to a safe place. Note the time. A restore may overwrite the traces you need to understand what ran.
- Assess the damage. What was changed or deleted, which tables, which time range, were there other writes after it.
- Restore from the best source. Often a backup or point-in-time recovery. Restore into a separate copy first, check row counts and a few records, then switch over or copy back the missing data. Know your recovery point: data written after the last backup needs another source.
- Communicate and review. Tell affected teams and users what happened and what is restored. Then write a blameless postmortem about the access and gates, not about the agent's "intent".
Before and after
Weak response:
Delete the broken table, re-run the agent with a clearer prompt, fix the data by hand.
Better response:
15:02 agent stopped: session ended by PID 31877 (verified command line)
15:04 deploy token revoked; shared DB password rotated
15:08 transcript, shell history and DB audit log copied to incident bucket
15:15 damage: orders table truncated at 15:01; backup from 14:00 available
15:30 restored backup to orders_restore; row count and 5 sample records checked
15:50 missing 14:00-15:01 orders replayed from payment provider events
What goes wrong
- Restoring first. The evidence is overwritten and you never learn what happened.
- Leaving the credentials alive. Another session or a leaked token continues the damage.
- Letting the agent fix itself. It acts on the same wrong understanding.
- Assuming the backup is complete. A backup is only as recent as its last run, and untested ones often fail.
- Killing by pattern. Stopping every process named "node" can take down unrelated production services.
Examples
Why evidence comes before restore
An agent truncated a table. The team restores immediately and the audit table is restored too, so the record of what the agent ran is gone. In the better run, they copy the transcript and logs first. The transcript shows the agent used a production connection string meant for a staging task, and that is the real fix.
Finding the recovery gap
The last backup is from 14:00, and the delete happened at 15:01. After restoring, the team knows 61 minutes of orders are missing. They replay those orders from the payment provider event log and compare totals with the provider dashboard.
Key points
- Stop the agent first, using its exact process or job ID, never a name pattern.
- Revoke and rotate the credentials it used before doing anything else risky.
- Preserve transcripts, command history and audit logs before any restore overwrites them.
- Restore into a separate copy first and verify counts and sample records.
- Review the permissions and gates that let the command run, not the agent alone.
Common mistakes
- Restoring data before copying logs and transcripts, which destroys evidence.
- Revoking only the agent session and leaving its token valid for other sessions.
- Letting the same agent repair the damage, using the same misunderstanding that caused it.
- Stopping processes by name or pattern, which can hit unrelated production services.
Check yourself · 2 of 3
Why preserve logs and transcripts before restoring data?
Check yourself · 3 of 3
The last backup is from 14:00 and the destructive command ran at 15:01. What must the plan include?
Practice items, not counted towards your mastery.
Start here
- Postmortem culture: learning from failure (Google SRE book) (opens in a new tab)BookFree
What a blameless postmortem is, what it contains, and how teams keep the habit alive.
- Incident response (Google SRE workbook) (opens in a new tab)BookFree
Worked incidents showing roles, handoffs and what a good response looks like in practice.
- Managing Incidents (Google SRE book) (opens in a new tab)BookFree
Incident command roles, a live incident document and clear handoffs.