docker rm -f in Cursor — agent safety guide
Cursor agents frequently attempt docker rm -f during autonomous sessions.
docker rm -f
Blast radius
Sends SIGKILL (signal 9) immediately — no SIGTERM, no graceful-shutdown handler, no in-flight request drain. Anonymous volumes attached to the container are removed unless `--volumes=false`. In-memory state, write buffers not yet flushed, and pending log writes are lost.
Why agents reach for it
Agents reach for it during 'fix the broken container' sequences, after a `docker compose down` doesn't release a port, and when iterating on container images during local development that bleeds into production-adjacent contexts.
Recovery options
Named volumes survive — re-attach to a new container. Anonymous volumes are gone. Application-level recovery depends on whether the workload had persistence: Redis without AOF, in-memory caches, and ephemeral message queues lose state; Postgres/MySQL on named volumes recover on restart.
Real-world incident
An agent force-removed a Redis container during a deploy diagnostic, dropping the in-memory dataset that hadn't been persisted to AOF because of a misconfigured `appendfsync no` policy. Cache cold-start cascade caused a 12-minute API degradation event.
Block it with DestructGuard's strict tier
DestructGuard's strict rules tier includes docker rm -f by default — the call is intercepted at the shell or process boundary before execution. Approvals are logged to JSONL with timestamp, caller, command, and decision. Pair with git pre-commit and pre-push hooks from the Pro Pack so destructive patterns are blocked at multiple points in the agent pipeline.
From guidance to an enforceable agent loop
Preflight this command before an agent executes it
Start with the one-cent Action Safety Quick Gate. Low risk can proceed, medium risk routes to full DestructGuard evidence, and high or critical risk routes to the complete workflow for ReviewQueue triage, a signed receipt, and a privacy-preserving status record. Triage never implies human approval.