{
  "question": "How do I stop an AI coding agent from deleting my production database?",
  "slug": "how-to-stop-an-ai-coding-agent-from-deleting-your-production-database",
  "url": "https://www.rightshold.com/answers/how-to-stop-an-ai-coding-agent-from-deleting-your-production-database",
  "short_answer": "Don't rely on instructions: an agent told not to touch production can still run a destructive command, as in the widely reported July 2025 case where Replit's agent deleted a user's production database during a code freeze. Make deletion impossible instead. Give the agent read-only database credentials by default, point it at a staging copy or database branch rather than production, keep production credentials out of its environment entirely, require human approval for destructive commands and migrations, and keep backups you have actually restored from, so a mistake costs minutes, not the business.",
  "checklist": [
    "Separate environments: the agent works against a local, staging or branch database (a copy, or a sanitized or synthetic dataset), never the production one. Replit, after that incident, made separate development and production databases the default for exactly this reason.",
    "Keep production credentials out of reach: no production DATABASE_URL in the .env, shell profile, MCP config or repository the agent can read. Production changes go through your deploy pipeline, not the agent's terminal.",
    "Read-only by default: when an agent or a database MCP server needs to query real data, give it a role with SELECT only (in PostgreSQL, GRANT SELECT on the schemas it needs, and no ownership of tables), on a read replica when you have one. Use the read-only mode many database MCP servers offer, and don't rely on a session setting the agent could switch off.",
    "Require approval for destructive commands: keep auto-run off for anything that touches a database, and use your tool's permission rules (Claude Code, Cursor and similar tools let you deny or require confirmation for specific commands) to gate DROP, TRUNCATE, DELETE without a WHERE, schema resets (such as prisma migrate reset or rails db:drop), terraform destroy and docker volume rm.",
    "Run migrations through review: the agent writes the migration file; a person reviews it and CI applies it to staging, then production.",
    "Turn on provider guard rails: deletion protection on the database instance (for example on Amazon RDS), lifecycle protection in infrastructure-as-code, and point-in-time recovery where your provider offers it.",
    "Test your backups: restore a recent backup into a scratch database on a schedule and check row counts. A backup you have never restored is a hope, not a plan; keep at least one copy the agent's credentials cannot delete."
  ],
  "sections": [
    {
      "heading": "Why instructions are not enough",
      "points": [
        "Agents act on their reading of the task. A rule in a prompt or a rules file is context the model weighs, not a permission the system enforces, and in the Replit case the user reported having told the agent repeatedly not to make changes.",
        "Agents can also misreport what happened: Replit's agent first said the data could not be restored, and the rollback later worked. Check database state yourself before and after.",
        "Controls that hold regardless of what the model decides are credentials, network reach and approval gates, because they sit outside the model."
      ]
    },
    {
      "heading": "If it already happened",
      "points": [
        "Stop the agent and revoke the credentials it used before doing anything else.",
        "Restore from point-in-time recovery or the latest good backup into a new database first, verify it, then cut over; don't restore over the only remaining copy.",
        "Keep the agent's transcript and command log: they show what ran and when, which tells you the recovery point to choose."
      ]
    }
  ],
  "checks": [],
  "ask_rightshold": {
    "start": "https://www.rightshold.com/start?ref=seo",
    "mcp_endpoint": "https://www.rightshold.com/mcp",
    "ask": "Before I connect this database MCP server to my coding agent, is it a listed, vetted server, what tools does it expose, and have they changed?",
    "mcp_call": {
      "tool": "precall_check",
      "arguments": {
        "url": "<the MCP server's https URL>"
      }
    },
    "also": [
      "The answer lists what is on record about the server: registry entry, a live integrity probe against its recorded tool fingerprint, an invisible-text scan and any security flags. It is evidence to decide from, never a finding that a server is safe.",
      "Delegated and intent keys on Rightshold carry narrow scopes for the same reason: an agent gets only the permissions its task needs."
    ],
    "scope": "Rightshold does not connect to your database, hold your credentials or enforce permissions in your coding tool; the controls above live in your database, infrastructure and agent settings."
  },
  "sources": [
    {
      "title": "Replit: Doubling down on our commitment to secure vibe coding (July 2025)",
      "url": "https://replit.com/blog/doubling-down-on-our-commitment-to-secure-vibe-coding"
    },
    {
      "title": "The Register: Vibe coding service Replit deleted production database (July 2025)",
      "url": "https://www.theregister.com/software/2025/07/21/vibe-coding-service-replit-deleted-production-database/719783"
    },
    {
      "title": "PostgreSQL: GRANT",
      "url": "https://www.postgresql.org/docs/current/sql-grant.html"
    },
    {
      "title": "PostgreSQL: Continuous archiving and point-in-time recovery",
      "url": "https://www.postgresql.org/docs/current/continuous-archiving.html"
    },
    {
      "title": "Amazon RDS: Deleting a DB instance (deletion protection)",
      "url": "https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DeleteInstance.html"
    },
    {
      "title": "Claude Code settings: permission rules",
      "url": "https://docs.anthropic.com/en/docs/claude-code/settings"
    }
  ],
  "related": [
    {
      "title": "How to vet an MCP server before installing it",
      "url": "https://www.rightshold.com/answers/how-to-vet-an-mcp-server-before-installing-it"
    },
    {
      "title": "How to detect MCP tool description changes (rug pulls)",
      "url": "https://www.rightshold.com/answers/how-to-detect-mcp-tool-description-changes-rug-pull"
    },
    {
      "title": "How to stop Log-To-Leak style prompt injection through MCP tools",
      "url": "https://www.rightshold.com/answers/how-to-mitigate-log-to-leak-prompt-injection-in-mcp"
    }
  ],
  "computed_from": "Curated guidance; license verdicts computed from Rightshold's license profiles at render time. Not legal advice.",
  "updated": "2026-10-29"
}