How I make sure an agent can't wipe my database

A couple of stories made the rounds this week, and they rhymed. In one, someone had an agent running in auto mode, and it modified their production database without asking, then apologized after the fact. In another, an agent deleted a live database and its backups in about nine seconds, through a token that held far more power than it ever should have. Different tools, same shape: a coding agent with production write access, no gate on the irreversible, and a safety net that turned out to be decorative.

If you're a vibe coder and this is the thing that keeps you up at night, here's the short version of how I think about it. The fix is almost never a more careful prompt. It's architectural. You give the agent credentials that physically cannot drop, truncate, or wipe your data, you put a human in front of anything irreversible, and you build the undo before you hand over the keys. The agent can be as reckless as it likes inside a blast radius you drew on purpose. Orient before you modify, and keep that radius small.

why does an agent in auto mode wreck production?

Auto mode is a trade. You give up the confirmation step to get speed, and for reformatting a component or renaming a variable that trade is fine. The problem is that the agent doesn't know which actions are cheap and which are final. To a model predicting the next token, DROP TABLE users and "rename this function" are the same kind of move: a step toward what it read as the goal. It isn't malicious and it isn't stupid. It's a confused deputy. It holds real authority, it's acting on your behalf, and it has no built-in sense that some doors only open one way.

Give that deputy a connection string to production and a role that can do anything, and you've built a machine that runs irreversible operations at the speed of a suggestion. The database doesn't care that a person didn't type the command. It runs what it's told by a credential that's allowed to tell it.

how do you stop a coding agent from deleting your database?

Three moves, in the order I'd build them.

First, least privilege at the data layer. The credential the agent uses should be able to read and write the rows your app touches and nothing else. No DROP, no TRUNCATE, no schema changes, no reach into the backup bucket. This is the same default-open lesson I wrote about in is your vibe coded app secure: a generator implements what the spec asks for and leaves everything else at its permissive default, so an unstated permission is an open door. State it. The agent that literally cannot run a destructive command is safer than the one you asked nicely not to.

Second, a human gate on anything irreversible. Reversible work stays in auto mode. The moment an action can't be undone, a schema migration, a bulk delete, a production deploy, it stops and waits for a person. This is a guardrail in the real sense, a gate that refuses, not a reminder in a doc the agent never reads. I went into what that actually means in what real guardrails look like: a guardrail is a check that can say no and make it stick.

Third, build the undo first. Tested backups that live somewhere the agent's credential can't reach. Reversible migrations. Commit and push often, so the code state is always recoverable. The part people skip is the timing. You build all of that before you hand the agent the keys, not after the first scare.

build the undo before the happy path

That third move is the one I care about most, because it's the discipline underneath the other two, and it's the one I had to prove to myself on this site.

This blog auto-ships. A scheduled agent drafts a post, runs it through gates, and commits it to the live site with no human pressing publish. That's an agent with write access to production, which is exactly the setup that wrecked those databases this week. The reason I sleep fine about it is the order I built it in. Before the drafter existed, I built and functionally tested the revert command, the thing that pulls a bad post back out. The undo shipped before the thing that needs undoing. Then I put the refusing gate in front of it: a three-leg check where the agent's draft only proposes, a validator and a set of greps measure, and a commit hook disposes by shipping or blocking. The agent never gets to approve its own work.

That's the principle, and it has a name I keep coming back to: build the failure surface before the happy path. Decide how the thing fails, and build the catch for it, before you build the part that goes fast. It feels backwards the first few times, because you're spending effort on a disaster that hasn't happened yet. That effort is the entire point. The people whose databases evaporated this week had the happy path and no failure surface, so the first time the failure ran, there was nothing underneath it.

the backup that wasn't there

The line in every one of these stories is some version of "but I had backups." Two problems quietly make that false. The backup is stale, because nobody tested the restore and the most recent working copy was months old. Or the backup lived inside the blast radius, on the same account, reachable by the same over-powered credential, so the delete took the safety net with it.

A backup you've never restored from is a hope, not a plan. The only backup that counts is one you've actually rehearsed bringing back, stored somewhere the agent's credential has no reach. And when the worst does happen, the instinct to fix it fast is the trap. Re-prompting the agent into the wreckage, asking it to undo what it did, usually grows the damage. Stop the agent. Assess from outside the system. Restore from the copy you know works. Orient before you modify applies hardest at the exact moment you least want to slow down.

If you're running agents against something you can't afford to lose, and you're not sure what their credentials could actually do on a bad day, that's worth mapping before it gets tested for you. If you want a second set of eyes on the blast radius, work with VibeKoded.

None of this slows vibe coding down in the way people fear. Auto mode still runs for the ninety percent of work that's reversible, and that work never stops. What changes is that the ten percent that could end you now has a gate in front of it and a net under it, both built before the agent ever touched the keys. The speed of vibe coding was never the risk. The risk was pointing that speed at something irreversible with nothing underneath it.

questions that keep coming up

Does a human gate kill the point of auto mode? No, because most of what an agent does is reversible, and that work never stops. The gate only fires on the small set of actions you can't take back. You're not reviewing everything, you're reviewing the handful of things that could end you.

Where should backups actually live? Somewhere the agent's credential cannot reach: a different account or provider, and restored from at least once so you know the restore works. A backup in the same blast radius is not a backup.

Isn't least privilege a pain to set up? It's an afternoon, once, and it's the cheapest insurance in AI orchestration. A credential that can't drop your tables is the difference between a bad morning and a company-ending one.

// part of the ai project rescue topic

// grab the free starter kit that makes your AI stop forgetting and stop guessing: get it →

// building with AI? the field manual has the structured lessons.

// hitting this on a real build? this is what I fix →