# How to stop an AI agent from dropping your production database

> A coding agent with a real admin token can run DROP, TRUNCATE or a bad Terraform destroy unattended. The fix is not a bigger warning: it is refusing the call unless a named human approves it first. The real approval gate, with the exact API shapes.

Source: https://scribase.com/stop-ai-agent-dropping-production-database

Claude Code, Cursor and other agents have already wiped real production databases this year by running a destructive command nobody reviewed first: a Terraform destroy, a migration with no WHERE clause, a restore from the wrong snapshot. The pattern in every public report is the same — the agent had a token that could do it, and nothing between the agent and production asked a person first. That is the actual fix: not a smarter agent, a gate.

## What actually happened in the real incidents

Public reports this year describe the same shape of failure: an agent (Claude Code, or Cursor running Claude) was given a token wide enough to touch production, it ran a destructive operation as part of normal-looking work — a Terraform apply that resolved to a destroy, a migration without a WHERE clause, a restore pointed at the wrong target — and nothing stopped the call before it ran. One report describes 2.5 years of submissions destroyed; another describes volume-level backups deleted in the same API call as the database. None of these needed an attacker. The agent did exactly what its token let it do.

## Sources

- [HN: "Claude Code wiped our production database with a Terraform command"](https://news.ycombinator.com/item?id=47278720)
- [HN: "An AI agent deleted our production database. The agent's confession is below"](https://news.ycombinator.com/item?id=47911524)
- [HN: "I dropped our production database and now pay 10% more for AWS"](https://news.ycombinator.com/item?id=47275157)
- [Show HN: "Clampd – Your AI agent can DROP TABLE. We block it in <10ms"](https://news.ycombinator.com/item?id=47514656)

## The fix is a gate, not a bigger warning

A system prompt that tells an agent "be careful with production" is not a control; it is a hope. The actual fix has to live in the API, after the agent decides to send the call, so it works even when the agent is confident it is right. On Scribase, a destructive call against production — a confirmed drop, truncate, delete or unconditional update, a destructive migration, a restore — from a token that is not an organization admin gets a `202 approval_required` instead of running, once the project has a named production approver. Nothing executes until that person clicks Approve.

_Turn it on: one field, one admin call_

```bash
curl -X PUT https://api.scribase.com/v1/organizations/acme/projects/web/prod-approver \
  -H "Authorization: Bearer $SCRIBASE_TOKEN" -H "Content-Type: application/json" \
  -d '{"email":"lead@acme.com"}'
```

_What the agent gets back instead of running the drop_

```json
{
  "status": "approval_required",
  "approval_id": "apr_5f0c9d3a7b1e4c2a9d8e6f01",
  "approver": "lead@acme.com",
  "operation": { "summary": "Run SQL: drop table legacy_orders" },
  "next": "Not run. Do not send the request again."
}
```

## Sources

- [Scribase docs: Production approver](https://docs.scribase.com/docs/agents/prod-approver)

[Full approval flow](https://scribase.com/approve-ai-agent-database-changes)

## Why scoped tokens alone are not enough

Least-privilege tokens help, but every one of the public incidents above involved a token that was supposed to have that access — a deploy or admin credential doing its normal job. A scope answers "can this token ever do this"; an approval gate answers the question a scope cannot: "should this specific request, right now, actually run". Scribase does both: the smallest useful scope by default (see the permissions page below), and the approver gate on top for production specifically.

[Scoping an agent token](https://scribase.com/ai-agent-database-permissions)

## FAQ

**Can an AI coding agent really drop a production database by itself?**

Yes, and it has happened in public, repeatedly this year, with no attacker involved: Claude Code running a Terraform command that resolved to a destroy, a migration without a WHERE clause, a restore pointed at the wrong snapshot. In each report, the agent had a token wide enough to make the call and nothing asked a human before it ran.

**Is giving the agent a read-only or scoped token enough to prevent this?**

It reduces the blast radius but does not remove the risk, because the agent still needs real write access to do its job on branches and previews. The incidents on record involved credentials that were supposed to have that access. The complete fix pairs a scoped token with a gate specifically on production: Scribase refuses a destructive call on production from a non-admin token unless a named human approves it, via a 202 approval_required response and an email with Approve and Deny.

**Does the approval step slow the agent down on everyday work?**

No — only destructive calls against production trigger it (confirmed drops, truncates, unconditional deletes or updates, restores, key rotations). Everyday schema work on a branch or preview environment runs immediately with no approval step; the agent is meant to do that work on a branch and only merge to production after a diff is reviewed.

**What if the approver does not answer in time?**

The request expires after 24 hours with nothing run, and the state changes to expired; the agent can send the request again to ask once more. A denial also runs nothing. Either way the stored request only ever executes on an explicit Approve click, and the audit log records every requested, approved, denied and expired step.

## Related

- [Approve an AI agent database change](https://scribase.com/approve-ai-agent-database-changes)
- [AI agent database permissions](https://scribase.com/ai-agent-database-permissions)
- [RLS for AI coding agents](https://scribase.com/rls-for-ai-coding-agents)
- [Coding agents hub](https://scribase.com/agents)
- [Give an agent a database branch per task](https://scribase.com/database-branch-per-agent-task)