Rightshold™ Sign up

Answers · agent controls

How do I build a kill switch for an autonomous AI agent?

Last updated

TL;DR: A kill switch is a check that every risky action has to pass, kept outside the agent's own process, that you can flip without the agent's cooperation, and that blocks when it can't get an answer. Put it in the tool layer (a hook, wrapper or proxy every tool call goes through), make it fail closed, and back it with the things the agent holds: credentials you can revoke and payment cards you can freeze. Stopping the process is the last resort, not the switch. Then test it: flip it during a run and confirm the next action is refused.

What should I check, step by step?

1. Write down what the agent can touch: tools, API keys, OAuth tokens, payment methods, databases, outbound network. Each one needs a way to be shut off that doesn't depend on the agent.

  1. Put one check in front of every tool call, in code the agent can't edit: a pre-tool hook, a wrapper around each tool, or a proxy that holds the real credentials. The check reads an on/off flag kept outside the agent's process.
  2. Fail closed. If the check errors, times out or can't be reached, the action must be refused, not allowed. Many hook systems default the other way, so check yours.
  3. Cover every path, not just your own functions. Built-in shell, browser and hosted tools often skip the hooks you add to custom tools.
  4. Back it with revocable access: short-lived tokens you can revoke, one card per agent you can freeze, and keys that belong to the agent alone, so turning them off doesn't break anything else.
  5. Make it reachable by the humans who need it: an owner (and an on-call backup) should be able to flip it from a phone in under a minute, and the flip itself should be logged with who and when.
  6. Keep two levels: a pause you can lift (block new actions) and a revoke that's permanent (burn the credential, issue a new one if you resume).
  7. Drill it. Flip the switch in a test run, confirm the next tool call is refused, then confirm resume works. A kill switch nobody has tested is a guess.

Where the check goes in common agent frameworks (checked Oct 30, 2026)

Claude Code: a PreToolUse hook runs before every tool call, MCP tools included, and can block it (exit code 2, or JSON with permissionDecision "deny"). Its docs say a hook that can't start, exits with any other code, times out or gets an HTTP error is a non-blocking error and the tool runs anyway, unless the hook sets onFailure: "block". Exit 1 does not block. Set onFailure: "block" on a kill-switch hook.

The layers under the switch

Credentials: revoke or rotate the keys and tokens the agent holds. Short-lived, per-agent credentials make this quick and keep the blast radius to one agent.

What can go wrong?

The flag is checked once at startup, so a long run never sees it flip.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “My agent is misbehaving. Revoke its credential now so every Rightshold check refuses it, reason rogue_behavior.”

One-click setup

{
  "tool": "revoke_agent",
  "arguments": {
    "subject_id": "crd_YOUR_AGENT_CREDENTIAL",
    "reason": "rogue_behavior",
    "note": "looping refunds, stopped by owner"
  }
}

Rightshold's switches stop actions only where your code asks Rightshold first. It can't stop a process, revoke your other providers' keys or freeze your cards; put the check in a tool layer the agent can't bypass and keep the real credentials there.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'