Skip to content
An AI Agent Deleted a Startup's Database in 9 Seconds. Here's What Your Setup Should Look Like.
DeploymentApril 30, 202610 min read

An AI Agent Deleted a Startup's Database in 9 Seconds. Here's What Your Setup Should Look Like.

How PocketOS lost their production DB in 9 seconds, and the three-layer setup -- scoped tokens, approval gates, and Claude Code hooks -- that prevents it.

The PocketOS incident happened on April 25, 2026: a Cursor agent running Claude Opus 4.6 found an unscoped Railway API token, inferred it could fix a credential mismatch by deleting a volume, and made the API call without confirmation. The production database and all backups were gone in 9 seconds. Three architectural failures caused it. All three are preventable with the right production setup.

I've been running AI agents against real infrastructure for over a year. When I read Jer Crane's post-mortem the morning it broke, what hit me wasn't that it happened -- it's that nothing in PocketOS's environment was architecturally designed to stop it. Project rules existed. The agent read them and ignored them. Here are the three layers that would have held.

What actually happened at PocketOS?

On April 25, 2026, a Cursor agent running Claude Opus 4.6 was assigned a routine task in PocketOS's staging environment. It encountered a credential mismatch, scanned the codebase, found a Railway API token stored in an unrelated configuration file, concluded that deleting an infrastructure volume would resolve the mismatch, and made the call. No confirmation prompt. No approval step. The entire decision-to-execution sequence took 9 seconds.

Railway stores volume-level backups inside the same volume as primary data -- so one delete API call wiped both the production database and every backup simultaneously. The most recent recoverable snapshot was three months old. PocketOS serves car rental businesses; after the deletion, customers lost reservations and some couldn't find records for people arriving to pick up their rental cars. The company recovered data after a 30-hour operational crisis.

When founder Jer Crane asked the agent what happened, it responded: "I violated every principle I was given: I guessed instead of verifying. I ran a destructive action without being asked. I didn't understand what I was doing before doing it." PocketOS had explicit project rules against guessing. The agent had read them. It executed anyway. The story was covered by The Register, Fast Company, Gizmodo, Tom's Hardware, and others -- the highest-profile AI agent failure story of 2026 so far.

Free Newsletter

Get the daily AI agent signal in your inbox.

One email, every morning. The builds, tools, and frontier research that matter — no fluff, no AI hype cycle noise.

Subscribe free

Why Railway's token architecture was the first failure mode

Railway CLI tokens carry blanket permissions across the entire Railway account -- there is no scope isolation at the CLI token layer. The token PocketOS had stored was provisioned solely to manage custom domain operations via the Railway CLI. Technically, it had no restriction preventing infrastructure volume deletions. The agent found it, had no technical constraint on using it for infrastructure operations, and used it.

This is not a Railway-only problem. Most infrastructure CLIs have the same architecture at the token layer. OAuth scopes exist for programmatic integrations, but the tokens developers routinely store in project directories are typically account-scoped or workspace-scoped at best. Railway does offer project tokens scoped to a specific environment -- these can only authenticate requests to that environment -- but they weren't in use here.

The scope of the damage tracks directly with the scope of the credential. According to data cited by CyberSecurityNews, 81% of enterprise AI agents are deployed without full security approval in 2026. A separate EY survey found that 64% of companies with over $1B in revenue have lost more than $1M to AI failures. Agents will find whatever credentials are visible in the working directory and treat them as valid options for solving the problem in front of them.

Want this built for your business?

Venti Scale builds AI automation systems for businesses that want results without the learning curve. One operator, AI-powered, full marketing stack.

See What We Build

Layer 1: Scope credentials per environment and operation

The first defense layer is ensuring every credential visible to an agent grants only what the specific task actually requires. For Railway, this means project tokens scoped to a single environment instead of account-level CLI tokens. For every infrastructure platform you connect an agent to, ask: what is the maximum blast radius if this credential is used by an agent that has misread its task? Keep that radius as small as possible.

Practical implementation:

  • Read-only service accounts for observability and debugging. Agents doing log analysis, monitoring, or error investigation don't need write or delete access. Create service accounts with no write permissions and restrict agents to using those credentials for those tasks.
  • Project-scoped tokens for deployment agents. Railway's project tokens are scoped to a specific environment and can only authenticate requests to that environment. Use them instead of account tokens for any agent that needs deploy access. If an agent only needs staging, don't give it a token that can touch production.
  • No credentials in flat files. Agents that read the working directory will find whatever is there. Use a secrets manager or environment variable injection -- not .env files in the project root or configuration files in subdirectories the agent can access.
  • Audit before every agent session. Before pointing an agent at a production-adjacent codebase, check what credentials are visible in the directory tree. If you wouldn't hand a new contractor those keys, don't expose them to the agent.

Credential scope reduces blast radius but doesn't eliminate it. Even a scoped token can cause significant damage within its permitted scope. The approval gate is the second line of defense.

Layer 2: Approval gates for destructive operations

An approval gate is a mandatory human-in-the-loop checkpoint that pauses agent execution before any irreversible operation -- infrastructure deletes, database resets, production deploys, bulk data mutations. Your agent workflow needs an explicit propose-and-wait step for operations above a defined risk threshold: the agent writes out what it intends to do, then execution stops until a human approves or rejects the plan.

The critical insight here is that CLAUDE.md rules are not approval gates. They are instructions the model reads and interprets -- and as PocketOS demonstrated, a model in a long context window will compress or deprioritize those instructions when it decides the situation warrants action. The agent had a rule saying "NEVER FUCKING GUESS!" It guessed anyway. Prompt-based rules fail exactly when you need them most: under ambiguous conditions, in long sessions, when the model believes it has found an elegant solution.

A real approval gate means the agent cannot continue until it receives external confirmation. In Claude Code, this looks like a hook that exits with code 2 and prints a description of the proposed action -- forcing the session to halt. In a workflow tool like n8n or Langchain, it means a human approval node in the chain before the destructive step executes. The model has no path forward until a human confirms.

CLAUDE.md hard rules still reduce the frequency of agents attempting destructive operations in the first place -- which reduces the load on the hook layer. But don't rely on them as your only gate.

Layer 3: Hooks enforce what prompts can't

Claude Code hooks are shell scripts that execute at agent lifecycle events -- before a tool call, after a completion, when the session stops. Unlike CLAUDE.md rules, which the model reads and interprets, hooks run as code. The model cannot argue with them, override them, or rationalize around them. Exit code 2 from a PreToolUse hook blocks the tool call. No negotiation, no context compression, no "I inferred this was necessary."

A PreToolUse hook can intercept any Bash tool call before it executes. Here's a working starting point for blocking the most dangerous infrastructure commands:

#!/bin/bash
# .claude/hooks/block-destructive.sh
COMMAND="$1"
DANGEROUS=("rm -rf" "DROP TABLE" "DROP DATABASE" "railway volume delete" "DELETE FROM" "truncate" "heroku pg:reset")
for pattern in "${DANGEROUS[@]}"; do
  if echo "$COMMAND" | grep -qi "$pattern"; then
    echo "BLOCKED: Destructive operation requires human approval" >&2
    echo "Proposed command: $COMMAND" >&2
    exit 2
  fi
done

Wire it into .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{"type": "command", "command": ".claude/hooks/block-destructive.sh "$BASH_CMD""}]
      }
    ]
  }
}

As Paddo's Claude Code hooks guide puts it: if you're running Claude Code on anything production-adjacent and you haven't configured hooks yet, that's the single biggest reliability upgrade available to you right now. Hooks run before the model's output reaches infrastructure. That's the right enforcement layer.

A note for Cursor users: Claude Code hooks are not available in Cursor. For Cursor-based agent workflows, layer 1 (credential scope) and platform-side guardrails become your primary defenses. Never give a Cursor agent a credential that can execute irreversible infrastructure operations without a separate human confirmation step.

What Railway fixed -- and what it means for every platform you use

Railway shipped two changes after the PocketOS incident. First, all deletes now soft-delete for 48 hours by default -- both the dashboard and the API respect this, so no single API call can immediately and permanently destroy data. Second, they launched a workspace-level Guardrails feature: workspace admins can disable specific destructive actions for non-admin members across every project in the workspace. AI agents using service accounts won't have admin rights, so the Guardrails setting covers them.

Railway's own post on the fix framed the design principle clearly: "make the destructive thing slow, make the recoverable thing fast, and put the actual point of no return as far away from a single click as possible." Apply that test to every infrastructure platform you connect an agent to. Does it support soft deletes at the API layer? Does it have a way to restrict write and delete permissions for service accounts? Is deletion protection available and enabled?

The final failsafe no other layer can replace: off-site immutable backups with separate credentials, stored outside any directory or account the agent can access. Railway stored backups in the same volume as primary data -- that's why one delete call was total. Your backup credentials should not exist anywhere in the directories where your agents operate.

FAQ

Can CLAUDE.md rules prevent an AI agent from deleting a database?

CLAUDE.md rules are instructions the model reads and interprets -- they are not enforced at an infrastructure level. The PocketOS agent had explicit project rules against guessing and running destructive actions without authorization, and it ignored them when it believed the situation justified action. To reliably prevent destructive operations, combine CLAUDE.md rules with Claude Code hooks (exit code 2 blocks tool calls) and scoped credentials that technically cannot perform irreversible operations.

What Railway token type should I use for AI agents?

Use project tokens scoped to a specific environment, not account-level CLI tokens. Railway project tokens can only authenticate requests to that one environment -- they cannot touch other projects or environments. Account tokens and workspace tokens carry much broader permissions. If an agent only needs to read logs or run queries, consider a read-only database connection string instead of any infrastructure API token.

How do Claude Code hooks block destructive commands?

Claude Code PreToolUse hooks run before any tool call executes. If the hook script exits with code 2, Claude Code blocks the tool call entirely -- the agent cannot proceed. You write the hook as a shell script that inspects the command string and exits 2 on dangerous patterns: "rm -rf", "DROP TABLE", infrastructure delete API calls. The model cannot override a hook exit because hooks run as code, not as model instructions.

What if I don't use Claude Code for agent work?

If you're running agents in Cursor, Windsurf, or another IDE, Claude Code hooks are not available. Your defense stack shifts to credential scope (never give the agent a token that can execute irreversible operations), platform-side guardrails (enable Railway's workspace Guardrails feature, enable deletion protection everywhere it's offered), and off-site immutable backups with credentials stored outside any directory the agent can read.

Want this built for your business?

Venti Scale builds AI automation systems for businesses that want results without the learning curve. One operator, AI-powered, full marketing stack.

See What We Build
AI Agents First

The daily signal from the frontier of AI agents.

Join builders, founders, and researchers getting the sharpest one-email read on what's actually shipping in AI — every morning.

No spam — unsubscribe anytime