When an AI Agent Deleted the Production Database: PocketOS, Replit and How to Prevent It
In April 2026 a Cursor agent running Claude deleted a company's production database and its backups in nine seconds. In 2025 a Replit agent did the same during a code freeze, and in 2026 Claude Code ran a terraform destroy on a live site. The model was not the root cause in any of them. Access was.
In April 2026, an AI coding agent deleted PocketOS's production database, and its backups, in nine seconds. The founder, Jer Crane, described it publicly: a Cursor agent running Claude Opus 4.6 was doing a routine task in staging, hit a credential mismatch, and decided by itself to fix it by deleting a storage volume. It found an API token in a file unrelated to its task, a token with what Crane called "blanket authority across the entire Railway GraphQL API", and ran the delete. There was no environment scoping and no confirmation step. A Replit agent did much the same in July 2025, during a code freeze. In February 2026 Claude Code ran a terraform destroy on a live education platform. The headlines blame the AI. The root cause was access: a credential that could destroy production, sitting where an agent could read it, against an API that didn't ask twice. Below: each incident, what vendors changed, and a checklist that stops it.
Can an AI agent delete your production database?
Yes, if its credentials allow it. An agent runs commands and API calls with whatever tokens it can find. If one of them can delete production, the agent can delete production, whatever its instructions say. Every case below follows that pattern.
| Incident | When | Agent | What was deleted | Outcome |
|---|---|---|---|---|
| PocketOS | April 2026 | Cursor, Claude Opus 4.6 | Production database and volume-level backups on Railway | Recovered by Railway, with gaps reported |
| DataTalks.Club | February 2026 | Claude Code | Production RDS database, VPC, cluster, automated snapshots | AWS restored a snapshot 24 hours later |
| AWS Cost Explorer | December 2025 | Kiro (Amazon) | An environment, deleted and recreated | 13-hour disruption in one region, per the FT |
| SaaStr (Replit) | July 2025 | Replit Agent | Production database during a code freeze | Data recovered, despite the agent saying rollback was impossible |
What happened at PocketOS
From Security Magazine's account and Decrypt, based on the founder's post of 26 April 2026:
- The agent was working on a routine task in staging.
- It hit a credential mismatch and decided, unprompted, that deleting a Railway volume would fix it.
- It searched for an API token and found one in a file unrelated to its task. That token had authority over the whole Railway API.
- It called
volumeDelete. No environment scoping, no confirmation. - In nine seconds the production database and its volume-level backups were gone.
- Afterwards the agent said it had guessed instead of verifying, acted without being asked, and broken its rule against destructive commands without user approval.
What happened next. Railway's founder Jake Cooper said the token was fully permissioned and the call hit a legacy endpoint that lacked Railway's "delayed delete" logic. Railway patched that endpoint to delay deletes and recovered the data, "30 minutes after I connected with Jer", after a support ticket had lapsed for more than a day. Decrypt reported that PocketOS restored operations from a backup about three months old, and that Crane said significant data gaps remained and he had retained legal counsel. Crane's own conclusion was that this was not one bad agent: he called for scopable tokens, stricter confirmations and backups that live apart from the data.
What happened when Replit deleted a production database
In July 2025, SaaStr founder Jason Lemkin was building an app with Replit's agent. During a code freeze, the agent deleted the production database, holding records for more than 1,200 executives and over 1,190 companies (Fortune). It then told him a rollback would not work. He recovered the data anyway.
Replit's CEO Amjad Masad called it "unacceptable and should never be possible" and announced the fixes (The Register): automatic separation of development and production databases, staging environments, forcing the agent to search Replit's docs, and a planning or chat-only mode so you can work with the agent without it changing anything.
Claude Code and terraform destroy (February 2026)
Alexey Grigorev, who runs DataTalks.Club, wrote up how he dropped his production database. On 26 February 2026 he deployed with Terraform through Claude Code from a new machine, without the state file. Terraform thought nothing existed and started creating duplicates. While cleaning up, the agent swapped in an older state file that described the real production stack and ran a destroy. The VPC, the RDS database with 2.5 years of course submissions, the cluster and the load balancers went, and "all automated snapshots were deleted too". AWS support found a snapshot on its side and restored it exactly 24 hours later.
His changes afterwards: backups outside Terraform's lifecycle, a daily automated restore test, deletion protection in Terraform and in AWS, Terraform state in S3, and agents that no longer execute commands. He reviews and runs every plan himself.
Amazon Kiro and AWS (December 2025)
In February 2026 the Financial Times reported that Amazon's own coding agent, Kiro, chose to "delete and recreate the environment", causing a 13-hour disruption in December 2025. Amazon disputed the framing (The Register): it called it "user (AWS employee) error, specifically misconfigured access controls, not AI", limited to AWS Cost Explorer in one of its two mainland China regions. Kiro asks for authorization by default, but the engineer's role had broader permissions than expected. Amazon then added "mandatory peer review for production access". Both sides land on the same lesson: the permissions decided the damage.
Why prompt rules don't save you
The PocketOS agent had a rule against destructive commands without approval. It broke it. The Replit agent ignored a code freeze. That is not a scandal, it is how these systems work: an instruction in a prompt is guidance the model weighs, not a lock. Whatever an agent's credentials allow, it can eventually do. So the controls that matter live outside the agent.
How to prevent an AI agent from deleting your database
1. No production credentials in development. The agent working in staging should hold credentials that can only touch staging. Production access is separate, rare and deliberate. Separate cloud accounts or projects for dev and prod make this hard to get wrong.
2. Scope every token. One environment, the minimum actions. A token that can read logs should not be able to delete volumes. Give agents a read-only database user by default.
3. Keep secrets out of files. Inject them at runtime from a secrets manager. A token sitting in a file is a token every tool and agent in that directory can find. And keep a list of them: when Railway itself was breached in October 2026, every customer had to rotate everything at once (what to rotate after the Railway breach).
4. Make production refuse destructive actions. Turn on deletion protection for production databases, in your infrastructure code and in the cloud console, so deleting one requires a deliberate change first.
5. Keep backups out of reach of the same credential. If one token can delete the database and its backups, you have one copy, not two. PocketOS's backups lived on the deleted volume. DataTalks.Club's snapshots went with the database.
6. Test the restore. A backup you have never restored is a hope. Run a restore on a schedule and check the data comes back.
7. Put destructive operations behind a human, through a separate channel. Not "the agent asks in the chat", but a change that needs a review the agent can't approve. No auto-approve on terraform apply or destroy, and no DROP or DELETE on production without a second person.
8. Make changes reviewable. Infrastructure changes as code, through pull requests, so a destructive change is visible before it runs. An AI reviewer such as Claude Code Review can read every one of those pull requests, but it comments, it never approves.
What we do
We use AI coding agents every day to build client software, so this is our problem too. What protects our production:
- Production databases have deletion protection on, set in our infrastructure code.
- Infrastructure changes go through pull requests in Terraform, reviewed, with history of who changed what.
- Production deploys come from releases, not from someone's machine, after the same image has run in staging.
- Secrets live in HashiCorp Vault and Google Secret Manager, injected at runtime, not in files in the repository.
- Database and admin access is only reachable from our private network, never from the internet. Details on our security page.
For the agents we build for clients, the same principle applies to the agent's tools: each tool declares whether it reads or writes, writes need a stronger permission, and changes are visible with one-step undo. Why we prefer undo to an approve button.
Related: AI agent security, vibe coding security, and we deleted the approve button.