Sooner or later an agent will do something nobody intended. It might delete the wrong branch, open fifty pull requests, post a credential in a public issue, or run a script it picked up from a poisoned README. The first time it happens, teams usually improvise. This runbook is meant to be copied into your own docs and adapted before that day comes.
It has five phases: stop, scope, rotate, review, resume. Each phase lists the questions to answer and the evidence to collect. Fill in the bracketed names for your own team.
Before anything happens
A runbook only works if a few things exist in advance:
- An owner per agent. Every agent, including the scheduled ones nobody thinks about, has a named human owner.
- An inventory of credentials. For each agent: which keys and tokens it holds, what they can do, where they are stored and how to revoke them.
- One way to stop everything. An organization-wide kill switch, and the names of the people allowed to pull it. Our post on designing a kill switch covers what it should do.
- A log you can trust. A record of what agents did, written somewhere they cannot edit it.
- A rehearsal. Run this runbook once on a calm day, with a harmless fake incident.
Phase 1: Stop (first minutes)
The goal is to stop the damage, not to understand it. Understanding comes next.
- Declare the incident in your usual channel and name an incident lead. One person decides; everyone else reports to them.
- Pull the kill switch if the agent is still acting, or if you do not yet know which agent it is. Do not spend minutes identifying the culprit while it keeps going.
- Stop the specific runs you can identify: running sandboxes, scheduled jobs, CI workflows that trigger agents.
- Pause the triggers: webhooks, schedules and queues that would start new agent runs, so releasing the kill switch later does not restart the problem.
- Write down the time of each step. The timeline will matter.
Resist two temptations: deleting the agent’s output, and “fixing” things by hand before you know what happened. Both destroy evidence.
Phase 2: Scope (the next hour)
Now answer: what did it do, with what access, and since when?
Find the start. Work backward from the visible damage to the first action that went wrong. The trigger is often earlier than the damage: an issue comment it read, a dependency it installed, a file it fetched.
List every action in the window. From your audit log, collect what the agent’s identity did between the start and the stop: commands run, files written, network destinations, API calls, messages sent, approvals requested.
List every credential it could reach. Not just the ones it used. Anything in its environment, its sandbox, its config files or its prompts counts as exposed if the agent was running untrusted instructions.
Find the blast radius outside your systems. Pull requests opened, issues commented on, messages posted, packages published, emails sent. These need cleanup beyond your own infrastructure.
Questions for the incident document:
- What was the agent asked to do, and by whom?
- What did it read that it should not have trusted?
- What could it do that it did not need to?
- Did any control fire, such as an approval request, a policy denial or a DLP block? Did anyone act on it?
Phase 3: Rotate (as soon as scope is known)
Treat every credential the agent could reach as compromised, whether or not you saw it used.
- Revoke first, then reissue. Revoking stops misuse immediately. Reissuing can wait until the incident lead is satisfied.
- Work from the inventory, not from memory: API keys, cloud credentials, repository tokens, database passwords, webhook secrets, signing keys.
- Check for persistence. Look for things the agent could have created to keep access: new keys, deploy keys, OAuth apps, webhooks, scheduled jobs, users added to groups.
- Revert what it changed, with review: merged code, config, permissions. Reverts go through the normal review process, not straight to production.
Phase 4: Review (within a few days)
Write a blameless review. Agent incidents tend to have the same few root causes, so check each:
- Untrusted input reached the agent with no marking or isolation: issue text, web pages, dependency files. See from prompt injection to code execution.
- The agent had more access than its task needed: a broad token, network it did not need, secrets in its environment.
- No human checkpoint stood in front of an irreversible action. See which actions should wait for a person.
- Code ran somewhere it could reach valuable things: a laptop, a shared CI runner, a production host.
- Nobody was watching: alerts existed but went to an unread channel.
Each finding should end in a change with an owner and a date. “Be more careful” is not a change.
Phase 5: Resume (deliberately)
- Fix the trigger that started it, or block it, before restarting anything.
- Restart one agent at a time, starting with the least privileged, and watch the first runs.
- Release the kill switch only once the incident lead agrees, and record who released it and when.
- Re-enable triggers gradually, so a backlog of queued work does not all start at once.
- Close the incident with a link to the review and its follow-ups.
Where Sandscale helps
If your agents run on Sandscale, several steps above have a direct counterpart:
- Stop. Every organization has a kill switch that stops its agents at once, on every plan, and turning it on or off is recorded.
- Scope. The audit log is hash-chained, so a change or a gap shows, and records sign-ins, sandboxes started and stopped, commands run, files moved, secrets used, approvals and policy changes, with who, when and where. Every plan can read it in the console or through the API; Team and Enterprise can export it for a period as evidence.
- Rotate. Personal API keys can be revoked at once with
DELETE /api/v1/account/api-keys/{id}or from the console, and every key has an expiry of at most 90 days, per the authentication docs. The security page says Vault leases end with the job. A secret a run could read still counts as exposed: rotate it at its source and store the new value in Vault, and later runs get the new one. - Review. Approval requests and decisions are recorded with who decided and why.
None of that replaces the runbook. Tools record and enforce; people decide what happened and what changes next. Write the runbook down now, while nothing is on fire.