TL;DR: To stop your AI agent from deleting your production database, make sure no credential it can reach is able to delete it, and put every delete behind a person. Deny destructive commands in the agent's permission rules, give it a scoped token instead of your account, deploy to a platform where deletes wait for a human, and keep a backup the agent's credential can't delete. To let Claude Code, Codex or Cursor deploy your app without letting it delete production, use Ployz: the agent deploys to your own servers, and every deploy, restart or delete your agent asks for waits for you to approve, with no setting that turns it off.
- Pick Ployz if you want Claude Code or Codex to deploy and manage your app on your own server or VPS without being able to delete your database. Deletes, deploys and restarts wait for a person, and the
ployz mcptoken can't approve them. - Deny destructive commands in Claude Code with deny rules and a
PreToolUsehook, but treat that as a seatbelt. Rules match text, so a command written another way gets past them. - Never leave a broad API token where the agent can read it. In April 2026 an agent found an account-wide Railway token on a developer's machine and deleted a production volume with one API call.
- Keep backups out of the agent's reach. In both 2026 incidents below, the backups went with the database.
- On Coolify, leave
deleteoff the agent's token. On Dokploy, filter the MCP server's tools. Neither asks a person before a delete.
An AI agent deletes a production database when it holds a credential that can, and decides deletion is a step toward the task it was given. Every fix below removes one of those two things.
What actually happened in the public cases
Three cases were reported in public with enough detail to learn from. None of the agents was asked to delete anything.
| When | Agent | What it deleted | How the data came back | Source |
|---|---|---|---|---|
| July 2025 | Replit Agent, building an app for SaaStr's Jason Lemkin | The app's production database, during a code freeze he'd told it to respect | The agent said a restore was impossible; Lemkin restored it with Replit's own restore feature | The Register, 21 Jul 2025 |
| 26 Feb 2026 | Claude Code, cleaning up duplicate AWS resources for DataTalks.Club | The RDS database, VPC, ECS cluster, load balancers and every automated snapshot, via terraform destroy | AWS support found a snapshot the account couldn't see and restored it 24 hours later | Alexey Grigorev's post-mortem, 6 Mar 2026 |
| April 2026 | A Cursor agent running Claude, at PocketOS, on a staging task | A production Railway volume, with one volumeDelete API call | Railway recovered it; its API deleted volumes instantly until that week | Railway's write-up, 29 Apr 2026, Tom's Hardware, AI Incident Tracker #1469 |
The details are worth reading, because the same three things went wrong each time.
The agent was fixing something else. Claude Code at DataTalks.Club was asked to remove duplicates. When the AWS CLI got awkward, it said "I will do a terraform destroy", after swapping in an old Terraform state file that described the whole production stack. Railway says the PocketOS agent "decided that deletion was a reasonable step toward fixing something unrelated."
The credential reached further than the task. The PocketOS agent "found a Railway API token stored locally on the user's machine", and Railway says it "was provisioned with account scoped access, the maximum access possible." An instruction in the prompt didn't help either: Lemkin had told Replit's agent to freeze code, and it deleted the database anyway.
The backups lived next to the data. terraform destroy took the RDS snapshots with the database. On Railway, the API path the agent called made the volume's backups "look unavailable in the UI." Both teams got their data back only because the provider had a copy the customer couldn't see.
What changed afterwards tells you where the fixes belong. Replit now keeps development and production databases separate by default, so "the Agent cannot make any change to the production database during development" (Replit, 29 Jul 2025). Railway made API volume deletes "soft delete for 48 hours", like its dashboard (changelog, 1 May 2026). Grigorev wrote that "Agents no longer execute commands" and "Every destructive action is run by me." All three fixes live outside the agent.
The four layers that stop it
Use all four. Each one covers a hole in the one above it.
- The agent's own permission rules and hooks. Cheap, local, and the first thing to set up. They match text, so they catch the obvious command and miss a clever one.
- Scoped credentials. A token that can't delete is the strongest fix you control. It works whatever the agent decides.
- A platform where deletes need a person. The check happens on the server, so the agent can't talk its way past it.
- A backup the agent can't delete. For the day the other three fail, or for a
DROP TABLErun over a database connection, which no deploy platform sees.
1. Claude Code permission rules and hooks
Claude Code evaluates "deny, then ask, then allow. The first match in that order determines the outcome" (permissions docs). Put the commands that destroy things on the deny list, the ones that change production on the ask list, and keep the agent out of your .env. In .claude/settings.json:
{
"permissions": {
"deny": [
"Bash(terraform destroy*)",
"Bash(railway delete*)",
"Bash(railway volume delete*)",
"Bash(dropdb *)",
"Bash(ployz org approval *)",
"Read(./.env)",
"Read(./.env.*)"
],
"ask": ["Bash(terraform apply*)", "Bash(psql *)", "Bash(ployz *)"],
"disableBypassPermissionsMode": "disable"
}
}
disableBypassPermissionsMode stops anyone, including you at 11 p.m., from starting a session that skips every prompt. To block an MCP tool, name it the way Claude Code does, mcp__<server>__<tool>.
Rules match the command's text, and the docs say so plainly: a rule denying git push doesn't catch "a push written another way, such as git -C . push." A hook can look inside the command. A PreToolUse hook that exits with code 2 blocks the call and hands its message back to the agent (hooks docs):
#!/bin/bash
# .claude/hooks/no-destroy.sh
cmd=$(jq -r '.tool_input.command // empty')
if grep -qiE 'drop (table|database|schema)|truncate |terraform destroy|volumeDelete' <<<"$cmd"; then
echo "Blocked: destructive command. Ask the user to run it." >&2
exit 2
fi
exit 0
Register it under hooks.PreToolUse with "matcher": "Bash". Two things to know from the docs: exit code 1 doesn't block, and a hook that times out lets the call through. A hook is a better seatbelt than a rule, but it's still one more text match.
Codex and Cursor have their own approval modes. I covered those, and how to make an agent ask before it deploys, in how to deploy an app with Claude Code.
2. Scoped credentials
The PocketOS agent didn't need to get past a rule. It found a token. So:
- Keep production credentials off the machine the agent runs on. A token in a file in your repo or home directory is a token the agent can read.
- Make one token per agent, with the narrowest scope and an expiry. Railway's project tokens, for example, are limited to one environment, where the PocketOS token reached the whole account.
- Give the database a role without
DROP. The agent's connection string, if it needs one at all, should point at a role that can read and write rows but can't drop tables. Never hand it the production superuser.
3. A platform where deletes need a person
This is the layer most setups skip, because few platforms have it. Here's what each one does when an agent with a valid credential asks to delete production. Docs checked 15 November 2026.
| Platform | Can the agent delete production without a person? | What stands in the way | Source |
|---|---|---|---|
| Ployz | No | Deleting a service or volume, detaching a volume, removing a domain or a server, and taking a project or environment off your servers wait for a person. The agent's token can't approve, and no setting turns it off | Destructive actions ask first |
| Railway | Yes | railway delete and railway volume delete in the CLI, which has a global --yes; the local MCP server's remove_volume needs confirm: true, which the agent sends. API volume deletes can be undone for 48 hours | CLI, MCP, changelog |
| Vercel | Yes | vercel project delete asks you to type the project name in a terminal; --confirm-name skips the prompt for scripts | vercel project |
| Render | Not through MCP; yes through the API | The MCP server can't delete. The same API key reaches every workspace and can delete through the REST API | Render MCP, API auth |
| Coolify | Yes, if the token has delete | write doesn't include delete. No approval step: "An MCP client can use every operation allowed by its token" | Coolify MCP setup |
| Dokploy | Yes, whatever the API key can do | Tools carry destructiveHint, so a client may prompt; DOKPLOY_TOOL_PRESET and tag filters trim the tool list | Dokploy/mcp |
| Replit | Not the production database during development | Development and production databases are separate by default | Replit |
A "destructive" hint on an MCP tool is a request to your client to ask you. Whether it asks depends on the client and its settings, and an agent running the CLI never sees the hint. A check on the platform's side holds whichever way the agent connects.
4. A backup the agent can't delete
Assume the first three layers fail once. Keep a copy of the database somewhere the agent's credential can't reach, and try a restore before you need one. Grigorev now restores last night's backup every night and runs a check query against it. That's the habit I'd copy.
This layer also covers what no platform sees. An agent with a connection string can run DROP TABLE users inside a database that stays up, and no deploy platform will ask anyone about it.
How to let Claude Code deploy without letting it delete
With Ployz, the agent gets a real deploy tool and the deletes stay with you. Paste this into Claude Code, Codex or Cursor:
Read ployz.dev/agents.md and deploy this repo to my server.
The agent installs the CLI and the Ployz skill, signs you in with a link you approve in the browser, and registers ployz mcp, the same tools as the agent in the dashboard. Then it deploys the repo to the server you rent.
Here's what the agent does on its own through ployz mcp, and what waits for you (CLI docs, Permissions):
| The agent does on its own | Waits for you |
|---|---|
| Create projects, add services and databases, stage changes | Every deploy and redeploy the agent asks for |
| Read logs, deployments, servers and volumes | Deleting a service or volume, detaching a volume, removing a domain |
| Start a service | Stopping or restarting a service |
| Save a change that removes nothing | Removing a server, a project or an environment, or turning an environment's protection off |
A delete the agent stages, like removing a service, deletes nothing until a deploy, and that deploy waits for you. Your agent's app shows what the call would remove, and you approve or deny it there. Your answer goes to Ployz Cloud with your own sign-in, not the agent's. An app that can't show the dialog gets approval_required and a link; you approve under Waiting on you in the dashboard, or with ployz org approval approve ID in a terminal, which asks you to type the organization's slug. Then the agent tries again.
The token ployz mcp login makes can't answer an approval, so the agent can't approve itself. Ployz's docs are frank about the edge: an agent running commands in your terminal acts with your own sign-in there. That's why ployz org approval is on the deny list in the settings above.
For deploys that don't wait, such as an agent in CI, make a Deploy token for one environment. It deploys there but can't take anything off your servers: a deploy that removes a service, a volume or a domain needs a Full as you token (Permissions). That's deploy access without delete access.
The database is harder to reach by accident too. Ployz databases have no public address, and opening a shell or forwarding a port are commands you run in your terminal, not tools the agent gets through ployz mcp. Keep ployz on the ask list, as above, so the agent can't run them in your terminal unasked.
Where Ployz fits
Ployz is built for coding agents on your own servers. Each step the agent would do by hand over SSH is one Ployz call, and every deploy, restart or delete your agent asks for waits for you to approve. I built it that way because an agent with a root shell and your provider's API key is the setup behind most of the incidents above.
What comes with it, on the servers you rent: push-to-deploy from GitHub, a preview environment for every pull request, one-click Postgres, MySQL, Redis and MongoDB, a restore point you can restore into a new volume from the dashboard, metrics for every service and server, and searchable logs. A new project's default environment starts Protected, so a member's deploy there waits for an owner or admin too. Ployz is free on any number of servers.
Let your coding agent deploy to your own server with Ployz, free.
FAQ
Claude Code deleted my production database. What do I do first?
Stop the agent, revoke the credential it used, and ask your provider for a restore before you change anything else. In both 2026 cases the provider had a copy the customer couldn't see: AWS found a snapshot, and Railway recovered the volume. Then work through the four layers above before the agent runs again.
How do I stop Claude Code from running destructive commands?
Put them on the deny list in .claude/settings.json, add a PreToolUse hook that exits with code 2 on patterns like DROP TABLE or terraform destroy, and turn off bypass mode with disableBypassPermissionsMode. Rules and hooks match text, so also make sure no credential the agent can read is able to delete production.
Which deploy platform is safe to give Claude Code or Codex access to?
Ployz, if you want the agent to deploy to your own servers: every deploy, restart or delete your agent asks for waits for you to approve, the agent's token can't approve it, and no setting turns that off. On Coolify, a token without the delete permission can't delete. On Railway, Vercel, Render and Dokploy, a credential that can delete will delete when the agent calls it, unless your client asks you first.
How can I let Claude Code deploy my app to production?
Let it deploy through a tool that keeps destructive steps with you. With Ployz, paste Read ployz.dev/agents.md and deploy this repo to my server. into the agent. Each deploy it asks for waits for one click from you, or you give it a Deploy token that can ship but can't remove anything. On other platforms, see how to deploy an app with Claude Code.
How do I let Codex or Cursor deploy and manage my app on a VPS?
Give it a CLI or MCP server for the VPS rather than a root SSH key. Ployz installs on your VPS with one command and gives Codex or Cursor ployz mcp and a CLI with --json on every command. Coolify and Dokploy have MCP servers too; see Coolify vs Dokploy.
Does telling the agent "don't touch production" work?
No. Lemkin told Replit's agent to freeze code, and it deleted the production database anyway. An instruction is part of the prompt the agent weighs; a permission check on the server is not.
Do I still need backups if anything risky waits for a person?
Yes. An approved delete deletes the data, and a DROP TABLE over a database connection never reaches the platform. Keep a copy off the database's server and test restoring it.
How I checked
I read the three incident write-ups linked above on 15 November 2026: The Register's report on Replit, Alexey Grigorev's own post-mortem, and Railway's post and changelog on the PocketOS deletion, with Tom's Hardware and the MIT AI Incident Tracker for the company and the agent. I left out figures I found only in secondary coverage, such as record counts and recovery times that sources disagree on. Platform behaviour comes from each platform's own docs on the same day: Railway's CLI and MCP pages, Vercel's vercel project reference, Render's MCP and API docs, Coolify's MCP setup page, Dokploy's MCP README, and Claude Code's permissions and hooks pages. The Ployz approval rules come from the Ployz docs on permissions, organizations and the CLI. I didn't try to make any agent delete anything.
Deploy your app on your own server with Ployz, and keep the deletes for yourself: get started.