AI-native
Why doesn't cancelling an AI agent stop it?
Because a workflow's cancel only stops your side from waiting. The command the agent started is a process on another machine, and it keeps running until something on that machine stops it. To really cancel an agent in a sandbox, kill its command, which ends its child processes too, wait until it reports it's no longer running, and then delete the sandbox. Stopping the sandbox only freezes the agent.
Updated November 25, 2026
What actually happens when you cancel?
Your workflow engine ends its own task. It doesn't know that the step it was waiting on started a process in a VM. In Sandboxer's guide on making a cancel actually stop an AI agent, a test client cancelled after 6 seconds; the agent in the sandbox carried on looping, step after step. An agent left running like that can still push a branch or call an API after you think it's gone.
Which kind of stop does what?
| You do | The agent's processes | The sandbox |
|---|---|---|
| Cancel the workflow | Keep running | Running |
| Kill the command | Ended, with their children; anything left after 5 seconds is force-killed | Running, nothing of the agent left |
| Stop the sandbox | Frozen with memory; a resume brings them back mid-step | Stopped |
| Kill, then delete | Gone, with the disk and snapshots | Gone |
| Let a deadline expire | Frozen, as with a stop | Stopped |
A real cancel is kill, confirm, then delete.
How do you kill an agent's command?
On Sandboxer, use sbx exec --kill with the process id, the SDK's kill() or the MCP server's kill_command tool. Each sends a polite stop signal to the command, its process group and every descendant it can find, including a dev server that left the group, then force-kills whatever is left after 5 seconds. In the guide's test the kill took a quarter of a second and reached all three processes. If your agent needs to save state, have it catch the stop signal and finish within 5 seconds. For an agent you drive by prompt rather than as a command, the CLI has sbx interrupt.
Why isn't stopping the sandbox enough?
Because a stop is a pause. Sandboxer saves the sandbox's memory when it stops, so a resume brings back the same processes; in the guide, the agent's loop picked up at the next step after the resume. If the "cancelled" step was pushing code, it does that after the resume. See pause and resume.
What if your cancel handler never runs?
Give every sandbox a deadline when you create it, so a crashed handler still has a backstop. Two cautions from the guide: idle pause doesn't stop an agent that's working, because a running command counts as activity, and a deadline stops the sandbox rather than killing the agent. Pair it with a cleanup job that deletes stopped sandboxes you no longer need, and see how to stop an AI agent that's going wrong for the steps beyond the sandbox.
Frequently asked questions
Does cancelling a workflow stop the AI agent's command?
No. It only stops your side from waiting. Kill the command where it runs.
Does stopping a sandbox kill the agent?
No. On Sandboxer a stop saves memory, so a resume brings the agent back mid-step. Kill the command, then delete the sandbox.
How long does an agent get to save its state when killed?
On Sandboxer, 5 seconds after the stop signal before anything left is force-killed.
Does idle pause stop a runaway agent?
No. A running command counts as activity, so the sandbox stays up until its deadline.