Tegoby Attention SpanBlogBook a demo

A swapped state file wiped production on AWS

Strict rules refuse key steps

In February 2026, Claude Code unpacked an old archive over the file Terraform uses to track what it manages, then ran an auto-approved destroy that deleted a production stack on AWS and its snapshots. With strict rules, Tego would refuse the key steps: the agent can't read your cloud keys or reach AWS, so the destroy would fail and you run deploys yourself. We reproduced the incident's steps under these rules to confirm it.

What happened?

On 26 February 2026 a developer let Claude Code run Terraform against AWS. Terraform is a tool that creates and deletes cloud resources, such as servers and databases, from config files. By about 23:00 the DataTalks.Club production platform was gone. He told the story in his post-mortem, How I Dropped Our Production Database and Now Pay 10% More for AWS, on 6 March 2026, and Tom's Hardware retold it the next day.

He wanted to move a second site from GitHub Pages to AWS. To save money, he added it to the existing DataTalks.Club setup. By his account, "Claude was trying to talk me out of it".

He had recently moved to a new computer, and Terraform's state file was still on the old one. The state file is Terraform's list of what it manages. Without it, Terraform believed nothing existed, so terraform apply (the command that makes the cloud match the config) created duplicate resources. The agent started deleting the duplicates with the AWS CLI, Amazon's command-line tool.

He pointed the agent at an archive of the Terraform folder from the old machine. "I didn't notice Claude unpacking my Terraform archive", he writes. The unpacking "replaced my current state file with an older one", one that described production. Tom's Hardware says he "uploaded the state file"; we follow his own account.

The agent then switched to a destroy, which it judged "cleaner and simpler than through AWS CLI". His timeline calls it "A Terraform auto-approve command": auto-approve skips the yes-or-no question Terraform normally asks first. A destroy deletes every object the state file lists, as the plan command docs describe destroy mode. The state now listed production, so production went. "All automated snapshots were deleted too."

He upgraded to AWS Business Support. "Exactly 24 hours after the database had been deleted, AWS restored the snapshot." One table alone held 1,943,200 rows.

His fixes: agents no longer run commands for him. He reviews every plan and runs every destructive action himself. He added deletion protection, backups outside Terraform, a daily restore test and state stored in S3, Amazon's file storage.

Why didn't the usual safety catch it?

Because the agent was him, as far as AWS could tell. The sources do not say where the AWS keys lived or which operating system he used. Claude Code runs as the user who starts it, so we infer its commands had his AWS credentials, with the right to delete a database and its backups.

And each step looked normal on its own. The duplicate apply was an ordinary command. The unpacking was an ordinary write inside the project folder. The destroy was auto-approved, so no question came back to him. Nothing between the agent and AWS asked whether an AI agent should be deleting production at all.

How it could have been prevented

You don't need to foresee a swapped state file to prevent this. The general habit: an agent that writes and plans infrastructure code shouldn't hold the keys or the network path that delete production. Keep both with the person. Then a wrong turn in the agent's reasoning stays a wrong file, and that is the developer's own fix: the agent writes and plans, he runs every apply.

Tego enforces that habit from outside the agent, with the Linux kernel, so nothing the agent says or runs can switch it off. It runs on Linux, and on a Mac or Windows inside a small Linux VM. Two parts of its strict setup do the work here. Secret variables from your shell, such as AWS_SECRET_ACCESS_KEY, never reach the agent, and Tego's built-in list of secret files, which includes the AWS credentials folder ~/.aws, can't be read. And the agent connects only to its model and the hosts you list, so every call to AWS, the destroy's included, is refused and written into Tego's record of the run.

Tego's strict setup is three built-in rule sets: the agent can't read your secrets, can only reach the hosts you list, and can only change files in the folders you name. After one normal run, Tego can also narrow the rules to what that run actually did.

In Tego's rules file, that's:

YAML
extends: [tego/no-secrets, tego/no-prod, tego/repo-only-writes]
fs:
  write: ["./infra/"]                    # the Terraform folder
net:
  allow: ["registry.terraform.io:443"]   # providers; no AWS host

Tego would not have stopped the unpacking. It doesn't know which state file is the real one, and it never asks an AI model to judge. But the record shows the archive tool writing the state file, which turns the post-mortem into a lookup.

The honest limit: give the agent AWS keys and AWS hosts so it can deploy, and the destroy goes through, unless you also add a rule refusing the command terraform destroy, which a shipped test refuses even when written as -chdir=infra destroy -auto-approve.

The lesson

The destroy ran exactly as asked, on a state file that listed production. An agent that holds production keys and can rewrite the file that decides what they act on can do this again. Keep irreversible commands out of the agent's reach, keep the state file in versioned remote storage, and keep backups out of reach of the same keys.

Sources (33 links)