# Designing a kill switch for AI agents: what it should stop, and how to know it works

> Source: <https://dev.to/sandscale/designing-a-kill-switch-for-ai-agents-what-it-should-stop-and-how-to-know-it-works-7fe>
> Published: 2026-11-23 01:07:19+00:00

**Recommendation:** Enforce your agent kill switch where work executes, not in agent code, and make your SDK treat the stop signal as non-retryable so workers don't hammer the switch or stampede when it's released.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

Most incident runbooks for software have a step that says "roll back" or "turn off the feature flag". Agent systems need an equivalent that is faster and blunter: stop every agent in the organization, now, and keep them stopped until a person decides otherwise.

It sounds simple. In practice teams discover during their first real incident that "stop the agents" means a dozen different processes in a dozen places, some of which retry happily when told to stop. This post covers what a kill switch should do, who should hold it, how client code should behave when it is on, and how to test that it works before you need it.

You will not use a kill switch often, and that is the point. Typical triggers:

In each case the question "which agent, exactly?" takes time to answer. The kill switch buys that time.

A useful kill switch is defined by what is still running after you pull it. Aim for nothing. Concretely, it should:

The first point is the important design choice. A switch that relies on each agent checking a flag is only as good as the least careful agent. A switch enforced where the work is executed does not depend on agent code at all.

Make it easy to turn on and harder to turn off.

Both actions should be performed by a person, not an API key in a script, and both should land in an audit log with who did it and when. After the incident, the log of when it went on and off is part of your timeline.

Your own code that drives agents has to cooperate, or it will fight the switch. The common failure is a worker that sees an error, waits five seconds and retries, forever. Against a kill switch, that worker generates noise and, when the switch is released, a thundering herd of retries.

Rules for client code:

A kill switch you have never pulled is a hypothesis. Rehearse it on a quiet afternoon:

Write down the results. Repeat after significant changes to your agent setup.

Every Sandscale organization has a kill switch that stops its agents at once, on every plan; the [approvals and policies docs](https://sandscale.dev/docs/concepts/approvals) describe it. Its use is recorded in the hash-chained [audit log](https://sandscale.dev/docs/concepts/audit) along with who did it, when and where.

Turning the organization switch on or off through the API is reserved for a person: the [API reference](https://sandscale.dev/docs/reference/api/approvals-policies) lists `person_required` and step-up confirmation among the answers for that call, and says the change and its audit entry commit together. Code can check the state with `GET /api/v1/sandbox/kill-switch`, which needs the `sandboxes:read` permission and reports whether the switch is engaged and since when.

On the client side, the TypeScript SDK raises a `KillSwitchError` when the switch stops a call, and it never retries that error itself. Our post on [handling sandbox API errors](https://sandscale.dev/blog/handling-sandscale-api-errors-typescript) shows a wrapper that treats it as stop-everything.

The switch is only half the story. The other half is a runbook that says who pulls it, when, and what happens next. Write that before your first incident, not during it.

*Originally published on the [Sandscale blog](https://sandscale.dev/blog/kill-switch-for-ai-agents).*
