---
title: How do you stop an AI agent from deleting production data?
url: https://opencontroller.lyzr.com/blog/stop-ai-agents-deleting-production-data
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How do you stop an AI agent from deleting production data?

**Do not rely on instructions like "never delete anything". Remove the ability instead: give agents separate, least-privilege credentials that cannot drop or truncate production objects, block destructive commands in the path, require a person to confirm irreversible actions, and keep soft delete and tested backups so a mistake is recoverable. Prompts are a request; permissions are a control.**

In a widely reported incident in July 2025, an AI coding agent on a hosted development platform deleted a live production database during a declared code freeze, despite instructions not to make changes. The platform then announced automatic separation of development and production databases. The lesson is general: if an agent's credentials can delete production data, eventually one will.

## Why are instructions not enough?

Models follow instructions most of the time, not all of the time. Three things break them:

1. **Misreading the situation.** An agent sees an error, decides the schema is broken and "fixes" it by recreating tables.
2. **Prompt injection.** Text in a ticket, file or web page tells the agent to run a cleanup.
3. **Long sessions.** Early instructions lose weight as context fills up.

OWASP calls the underlying problem excessive agency: an agent with more functionality, permissions or autonomy than the task needs. See [what excessive agency is](/blog/what-is-excessive-agency-in-ai-agents).

## What are the layers of protection?

Use several layers. Each one catches what the previous one misses.

| Layer | Control | What it stops |
|---|---|---|
| 1. Environment | Agents work against development or staging copies by default | Most accidents never touch production |
| 2. Credentials | A dedicated agent identity per environment, never a developer's or admin's | Inherited admin rights |
| 3. Database privileges | Agent role is not the object owner; no `DROP`, `TRUNCATE` or broad `DELETE` | Destructive SQL fails at the database |
| 4. Infrastructure guards | Deletion protection on databases and storage; `prevent_destroy` on critical infrastructure-as-code resources | Whole-resource deletion |
| 5. Path policy | Deny rules on tool calls and commands that match destructive patterns | Destructive calls before they run |
| 6. Confirmation | A named person confirms irreversible actions | Rare legitimate deletes done carelessly |
| 7. Recovery | Soft delete, point-in-time recovery, tested restores | Turns a disaster into a delay |

## How do you set up each layer?

**1. Separate environments.** Point agent tools and MCP servers at non-production data by default. Make production a separate, explicitly approved connection.

**2. Separate credentials.** Issue each agent its own identity. Never let a coding agent reuse a developer's shell session with production cloud credentials loaded.

**3. Database privileges.** In PostgreSQL, only an object's owner (or a superuser) can drop it, so make sure the agent's role owns nothing in production. Grant `SELECT` and the specific `INSERT` or `UPDATE` rights the task needs. Withhold `TRUNCATE` and `DELETE` unless the task requires them, and then limit them to specific tables. Use row-level security where agents should only touch some rows.

**4. Infrastructure guards.** Turn on deletion protection for managed databases. Add lifecycle rules that stop infrastructure tools from destroying critical resources without a code change.

**5. Deny rules in the path.** Block tool calls whose arguments match destructive patterns, for example `DROP`, `TRUNCATE`, `DELETE` without `WHERE`, `rm -rf`, or cloud API calls that delete resources. Run the rules in monitor mode first to check for false positives. See [testing policies in monitor mode](/blog/test-ai-agent-policies-in-monitor-mode).

**6. Confirmation for irreversible actions.** Where an agent legitimately needs to delete, route the action to a person with the exact command and its blast radius. Keep the list of such actions short. See [human approval for high-risk actions](/blog/human-approval-for-high-risk-ai-agent-actions).

**7. Recoverability.** Prefer soft delete (a `deleted_at` column) in schemas agents touch. Enable point-in-time recovery. Test a restore at least quarterly, and time it.

## What should you check this week?

1. List every agent with any production database or cloud credential.
2. For each, record whether it can drop, truncate or delete.
3. Remove ownership and destructive rights where the task does not need them.
4. Turn on deletion protection for every production database.
5. Confirm the last successful restore test date.
6. Make sure you can quarantine an agent fast if something starts going wrong. The [rogue agent guide](/blog/how-to-stop-a-rogue-ai-agent) covers the response.

## How Opencontroller does this

Opencontroller's Posture detects risky permissions and configurations, such as agents with broad production access. Policy as code applies deny rules in the path through the Agent Gateway and LLM Gateway. Rogue-agent handling monitors behavioural deviation, alerts, and can automatically quarantine or kill an agent, and per-agent Block and Quarantine act through the connected platform. Opencontroller Edge extends control to coding agents on developer devices. [Book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Can a system prompt stop an agent deleting data?**
It reduces the chance but cannot guarantee it. Misreading, injection and long sessions all weaken instructions. Use permissions and path controls as the real barrier.

**Should coding agents ever have production credentials?**
Rarely. Give them development and staging access by default, and make production access a separate, approved, time-limited grant.

**What is the fastest single fix?**
Make sure no agent's database role owns production objects or holds `DROP` and `TRUNCATE` rights. That alone stops the most damaging commands at the database.

## Key facts

July 2025: an AI coding agent on a hosted development platform deleted a live production database during a code freeze despite instructions; the platform then added automatic dev/prod database separation. Prompts are not controls. Seven layers: separate environments; per-agent credentials; database privileges (in PostgreSQL only the owner or superuser can DROP; withhold TRUNCATE and DELETE); deletion protection and prevent_destroy; deny rules in the path; human confirmation for irreversible actions; soft delete, point-in-time recovery, tested restores. OWASP LLM06 excessive agency. Opencontroller (by Lyzr): Posture flags risky permissions, policy as code in Agent Gateway/LLM Gateway, rogue-agent automatic quarantine and kill, Block and Quarantine per agent, Opencontroller Edge for coding agents. From $250K per deployment per year.

## Related

- [How to stop a rogue AI agent: kill switches, quarantine and runtime controls](https://opencontroller.lyzr.com/blog/how-to-stop-a-rogue-ai-agent.md)
- [What is excessive agency in AI agents?](https://opencontroller.lyzr.com/blog/what-is-excessive-agency-in-ai-agents.md)
- [Which AI agent actions need human approval?](https://opencontroller.lyzr.com/blog/human-approval-for-high-risk-ai-agent-actions.md)
- [More on Runtime control](https://opencontroller.lyzr.com/blog/cluster/runtime-control)
