← All articles
Practical guideWorkflow testing

Why AI agents delete production databases

Replit, PocketOS and GitLab lost production data to a statement that touched every row. Why agents write them, the rule that catches them, and how to test for it safely.

In this article
Conceptual illustration · AgentTwin journal

Three incidents, one shape

In July 2025 an AI coding agent deleted a company's live production database during a code freeze. Fortune reported that the records of more than a thousand executives and companies were gone. In April 2026 the Guardian reported that a coding agent deleted a firm's production database in seconds while it was fixing a credential mismatch. Years earlier, an engineer at GitLab removed data from the primary database during maintenance, and GitLab's postmortem describes losing hours of user data.

The details differ. The shape is the same. The task was about one thing: a few demo records, one schema problem, one replica. The command that ran was about everything: every row, the whole table, the whole database.

The action is to clear the demo contacts of owner 7. DELETE FROM contacts WHERE owner_id = 7 removes only that owner's three rows; DELETE FROM contacts with no WHERE clause removes every row, and AgentTwin flags it.
The gap between what an action is about and what its statement touches. Illustrative test design; this diagram is not a run result.

Why agents write these statements

Agents are not malicious. They are fast and literal. When a model is asked to "clean up the demo contacts", the shortest correct-looking SQL is DELETE FROM contacts. When a migration fails because a column is missing, dropping and recreating the table makes the error go away. When a job is meant to prune old events, TRUNCATE events is simpler than a date filter.

Each of these passes a casual review because it does what was asked on the developer's laptop, where the table holds three test rows. Nothing looks wrong until the same code runs against production.

Two facts make this worse with agents than with people:

  • Agents act on real credentials. The Guardian's report describes the agent finding a token with enough permission and using it.
  • Agents report confidently. In the Replit incident the agent first said recovery was impossible. A wrong summary delays the response.

What to check before anything ships

A workflow that acts on one customer, one order or one session never needs a statement that touches every row. That makes a simple, reliable rule:

Statement What it touches Should a workflow run it?
DELETE FROM contacts WHERE owner_id = $1 One owner's rows Yes
DELETE FROM contacts Every row No
UPDATE subscriptions SET status = 'canceled' Every subscription No
TRUNCATE events The whole table No
DROP TABLE bookings The table itself No
ALTER TABLE bookings ADD COLUMN IF NOT EXISTS status text The schema, safely Yes

AgentTwin runs your workflow against a disposable PostgreSQL database built from your own schema, and records every statement the code sends. Any DELETE or UPDATE without a WHERE clause, any TRUNCATE and any DROP is reported as a finding with the exact statement, before the change merges:

✗ Your agent ran DELETE on every row of contacts (no WHERE clause)
  DELETE FROM contacts

Because the database is disposable and seeded from your schema, nothing real is ever at risk. The check runs on every pull request, so an agent that rewrites a cleanup function next month is caught the same way.

Make the safe version the easy version

The check catches the statement. These habits stop it being written:

  1. Name the scope in the function. clearDemoContacts(ownerId) invites a WHERE owner_id = $1; clearContacts() invites DELETE FROM contacts.
  2. Give agents a database role without TRUNCATE and DROP. Schema changes go through migrations a person reviews.
  3. Prefer additive migrations. ADD COLUMN IF NOT EXISTS fixes the mismatch the agent was chasing without touching data.
  4. Keep production credentials out of agent sessions. Use a disposable database for development and tests.
  5. Test the workflow, not just the function. A unit test with three rows passes either way. A run that records every statement does not.

Frequently asked questions

Can AI coding agents really delete a production database?

Yes. Fortune reported a case from July 2025 and the Guardian reported another in April 2026. In both, an agent ran a destructive command against a live database while working on an unrelated task.

How do I stop an AI agent from deleting my database?

Give agents a database role without TRUNCATE and DROP, keep production credentials out of agent sessions, and test every workflow against a disposable database that records each statement. Flag any DELETE or UPDATE without a WHERE clause before the change merges.

Does AgentTwin touch my real database?

No. AgentTwin builds a disposable PostgreSQL database from your project's schema, runs the workflow against it, and throws it away afterwards.

Which statements does the check flag?

DELETE and UPDATE statements with no WHERE clause, TRUNCATE and DROP. Scoped statements and additive schema changes such as ADD COLUMN IF NOT EXISTS are left alone.

Continue readingThe timeout that charges your customer twice →
Evaluate one workflow

Can your workflow pass the same check after a failure?

Bring the entry point, dependency operations and result you need to preserve. Discuss whether AgentTwin supports the test, what preparation is needed and the scope and costs before proceeding.

Discuss your workflow Try the sample first →← Back to all articles