viberrr
Scan my site
The field guide

Safe to hand to an agent

Coding agents now write, run and ship code for you. Most of the damage they do doesn't need a hacker. It needs an agent doing exactly what your codebase allowed: a test that runs against the live database, a key it could read, a delete it was permitted to run. This is the practical guide to finding those openings and closing them with controls that actually hold.

Published

Illustration with a sample app, drawn from this article.

The short answer

Keep production data and credentials out of the agent's reach, protect the branch that goes live, and back every rule you care about with a control: a guard that asks first, a check that must pass, a role that can't do damage. A rule written in a file is a request, not a protection. Then try to get round your own guards before you trust them.

01 · The pattern

No attacker required

When people imagine an AI agent causing harm, they picture someone tricking it. That happens, but the more common story is quieter. The agent is given access so it can do its job. The setup gives it more than the job needs. Then, while doing something reasonable, it does something irreversible.

The best-known case is a widely reported one from July 2025. A founder testing an AI app builder told its agent not to make changes during a code freeze. The agent deleted the production database anyway. Its development and production environments shared the same database, so a step that looked like housekeeping reached real data. The company behind the tool responded by promising automatic separation of development and production databases (Fortune, The Register).

Look at what went wrong and none of it is exotic. A rule was given as an instruction rather than a control. The agent could reach production data it never needed. Test and live data weren't separated. Each of these can be found in a codebase before anything happens, which is what the rest of this guide is about.

What your agent should be able to reach

agent
  • Your project files
    Inside its reach: what it needs to do the job.
  • Test data and local tools
    Inside its reach: what it needs to do the job.
  • Production credentials
    Outside its reach: a mistake here is irreversible.
  • Live data and backups
    Outside its reach: a mistake here is irreversible.
02 · The principle

A rule in a file is a request

Every agent tool lets you write instructions: AGENTS.md, CLAUDE.md, .cursorrules, project rules. They're useful. They shape how the agent works most of the time. But an instruction is read, weighed and usually followed. It isn't enforced. Under pressure, with a long task, a confusing error or an ambiguous request, an agent can decide that this case is the exception.

So for each rule that protects something you can't afford to lose, ask one question: what stops this from happening if the agent ignores the rule? If the answer is “nothing”, the rule is a request. Turning requests into protections is the core of agent safety, and it's usually straightforward.

The same mistake, two setups

A rule in a filerule (text)live dataAIReaches live dataA controlguard: asks you firstlive dataAIStopped. A person decides.
Rule

"Never push to main."

Protection: the live branch requires a pull request and passing checks; direct pushes are refused by the platform.

Rule

"Don't touch the production database."

Protection: the agent's credentials can't reach production, or reach it read-only.

Rule

"Ask before deleting anything."

Protection: a hook stops destructive commands and asks a person, and refuses outright in auto modes.

03 · The foundation

Get healthy first

Agent safety sits on top of ordinary engineering health. If tests already touch real data, or nothing checks a change before it goes live, no agent rule will save you. These five basics come first, and most can be set up in an afternoon with your agent's help. If your app is already live, run a security check of the app itself first: the leaked API key and the open Supabase table are the two most common problems.

01

Tests that never touch real data

Tests run against a local or throwaway database, and the test setup refuses to start if it's pointed anywhere else. Keys for real services are cleared before tests run, and requests to real hosts fail.

02

A check on every change

Every change runs the same automated checks (types, lint, tests, a build) before it can merge. The live branch only accepts changes that passed them.

03

Builds that need no secrets

The project builds with no keys present. That proves secrets are read at runtime from the environment, not baked into the code where an agent, or a visitor, can find them.

04

Errors you'll actually see

Errors from the live app go somewhere a person reads, with sensitive data stripped before they leave. An agent that breaks something at 2am should leave a trail.

05

Limits on anything public

Sign-up, sign-in, contact forms and anything that costs money per call (AI features especially) are rate-limited, so a mistake, or a stranger, can't run up the bill.

04 · The checklist

The risks to find

These are the openings that turn an agent's mistake into a loss. Each has a tell you can look for and a fix that closes it. They're ordered roughly by how much damage they can do. Hidden instructions in config files are a related risk with their own write-up: the malware hiding in your config files.

01

Test or dev settings pointing at production

When the test database is the live database, every test run and every agent experiment happens on customer data. A cleanup step meant for a scratch database empties the real one.

The tellYour test setup, .env files or docker-compose name a production database host, or there is only one database at all.

The fixPoint tests at a local or container database, and add a guard in the test setup that stops if the host isn't local.

02

Keys and tokens the agent can read

An agent can only misuse access it has. Production database URLs, cloud credentials, payment keys and personal access tokens sitting in files or the shell are all within its reach.

The tellProduction keys in the repository or .env files, cloud credentials in your home folder, broad tokens in environment variables, or a default profile that points at production.

The fixKeep production credentials out of the development environment, rotate any that were ever committed, and give the agent the narrowest token that does the job.

03

Deletes aimed by a variable

A delete whose target comes from a variable, a pattern or a link can resolve to something far larger than intended, such as the project root or the home folder, if the variable is empty or the input unexpected.

The tellScripts with recursive deletes built from variables or arguments, scripts without strict error settings, cleanup that follows links.

The fixFail on unset variables, resolve the full path and refuse anything outside the project, and print what would be deleted before deleting it.

04

Infrastructure one command can destroy

If the same access that deploys the app can delete the database, its backups and the project itself, then one wrong command loses everything at once.

The tellDatabases without deletion protection, backups stored where the deploy token can delete them, auto-approve flags in infrastructure scripts.

The fixTurn on deletion protection for data, store backups where the agent's credentials can't reach, and remove auto-approve from anything that can destroy.

05

Push and publish rights with no gate

If anything can push straight to the live branch, an agent's bad change goes live as fast as a good one, with no check in between.

The tellThe live branch can be force-pushed or deleted, merges don't require passing checks, or tokens with broad rights (any repository, deletion) are in reach.

The fixProtect the live branch: no deletion, no force-push, checks required before merge. Use a token scoped to one repository with only the rights it needs.

06

Tools that spend money or send messages without a cap

Payment APIs, email and SMS senders, ad platforms and paid AI calls do real-world things. A loop or a misunderstanding can send a thousand emails or spend a month's budget in minutes.

The tellTools or scripts that charge cards, send messages or call paid APIs with no per-call cap, recipient allowlist or confirmation.

The fixAdd caps per call and per day, allowlists for recipients during development, explicit units on amounts, and a human confirmation for anything irreversible.

07

AI agents in CI reading untrusted input

An agent that runs in your CI and reads issue text, pull request comments or code from strangers can be instructed by them. If that job can also see secrets or push code, a comment becomes an attack.

The tellWorkflows that run an AI agent on issues, comments or pull_request_target events, with write permission or secrets in the same job.

The fixLeast-privilege permissions on every workflow, no secrets in jobs that read untrusted input, and no shared caches between those jobs and releases.

08

Unpinned add-ons and hidden instructions

MCP servers, hooks, plugins and skills run with your agent's access. One pulled at the latest version can change under you. Instructions can also hide in rule files as invisible characters.

The tellMCP configs using @latest or npx -y, hooks or skills you don't recognise, permission-bypass flags in scripts, invisible Unicode in rule files.

The fixPin versions, remove what you don't use, give servers read-only tokens where they only read, and strip hidden characters from rule files.

09

Auto-approve modes and safety nets that don't load

Modes that let an agent approve its own actions remove the last pause before a mistake. Safety nets set up as shell aliases often don't load in the agent's shell at all, so they protect nothing.

The tellFull-access or auto-approve modes used for routine work; protections defined as aliases in your shell profile; no deny rules for destructive commands.

The fixKeep destructive commands behind a prompt the agent can't answer itself, put guards in scripts or the agent's deny rules rather than aliases, and sandbox the agent to the project folder.

10

Projects inside synced folders

Cloud-synced folders can hold placeholder files that look present but aren't. Tools that copy and then delete can lose the only real copy.

The tellThe project lives in iCloud, Dropbox or OneDrive, or contains zero-byte or online-only files.

The fixMove projects out of synced folders, and have scripts verify size and content after copying, before deleting anything.

05 · The controls

Make the rules real

Once you know which rules matter, back each one with something that holds when the agent doesn't. These are the controls that do it, roughly from simplest to strongest. The references: Claude Code hooks for guards that run before each action, GitHub rulesets for protected branches and required checks, the Model Context Protocol for what MCP servers can do, and the OWASP Top 10 for LLM applications for prompt injection and excessive agency.

Hooks that ask you first

Most agent tools can run a check before each action. Use it to stop and ask before anything that changes production, deletes data or ships code: a real prompt, not a line of text the agent may or may not honour.

In auto modes, refuse, don't ask

In a mode where the agent approves its own actions, a guard that "asks" can be answered by the agent itself. In those modes the guard has to refuse outright, and say why, so a person changes the mode deliberately.

Checks that must pass

Make the live branch require passing checks, so the rule "never ship broken code" is enforced by the platform rather than remembered by the agent.

Roles that can't do damage

Give the agent read-only database roles and narrowly scoped tokens. A rule like "don't modify production" is strongest when the agent simply can't.

Warnings where the agent reads them

For a risky command that has to stay, make its output name the hazard and the consequence ("WARNING: this database is production; this drops tables"). Agents read output closely. A clear warning at the moment of action often works better than a rule repeated in a file.

Name the safe command beside the rule

Next to each rule, say what to do instead: "run tests with make test-local", "deploy only through the release workflow". An agent with a clear safe path is less likely to improvise a risky one.

06 · The test

Prove it

A guard you haven't tested is a guess. Before you rely on one, try to get round it, and ask a second agent to try too, with a fresh view and no stake in it working. Guards that pattern-match commands are especially easy to slip past: a different spelling, a wrapper, a variable. The simplest guards are often the strongest. A guard that asks whenever something looks risky, even at the cost of an extra click, beats a clever one that tries to tell safe from unsafe and gets it wrong.

  • Try to break each guard yourself, then ask a second agent to try. Fix what it finds, and test the fix again.
  • Check that your checks actually run. A check that silently never ran looks exactly like one that passed. Look at exit codes and logs, not just the absence of errors.
  • List the fixes only you can make: branch protection, account settings, backups, token scopes. An agent can tell you where to click, but these settings belong to you.
  • Re-run the audit after any change to your tools, tokens or agent access. Setups drift quietly.
07 · Copy and paste

The audit prompt

Paste this into your agent from inside your project. It audits first, changes nothing, and waits for your approval before fixing anything. Replace the last line with your own stack.

Paste into your agent
Audit this project and my development setup for the risks below. Audit first and change nothing.

Rules for this audit:
- Never print secret values or use any credential. Show names and file paths only.
- For each finding: file:line, why it's dangerous, and the fix.
- Rank findings by how much damage they could do. Top 3 first.
- List anything outside this repository (accounts, tokens, settings, backups) as manual steps for me.
- Wait for my approval before changing anything.

Check:
1. Test, dev and preview settings (.env*, test setup, docker-compose, database config) that point at a non-local or production database, especially if tests reset, migrate or delete data.
2. Credentials my shell and tools can read: environment variable names, cloud CLI credentials, tokens, keys in the repository. Is the default profile production?
3. Recursive deletes whose target comes from a variable, pattern or link. Scripts without strict error settings.
4. Infrastructure one command can destroy: databases without deletion protection, backups the same token can delete, auto-approve flags.
5. Rules that exist only as text (AGENTS.md, CLAUDE.md, .cursorrules). For each, what actually enforces it?
6. Is the live branch protected (no force-push, no deletion, checks required)? What can my tokens do?
7. Is the project inside a cloud-synced folder, with placeholder or zero-byte files?
8. MCP servers, hooks, plugins and skills: unpinned versions, unknown sources, permission-bypass flags, hidden Unicode in rule files.
9. CI workflows that run an AI agent on untrusted input (issues, comments, pull_request_target) with secrets or write access.
10. Auto-approve or full-access agent modes, and safety nets that don't load in the agent's shell.
11. Tools that spend money or send messages without a cap, allowlist or confirmation.

My stack: [describe it, e.g. Next.js on Vercel with Supabase and Stripe].
08 · Keep it

Keep it as a skill

To run the same audit again without pasting, save it as a skill. In Claude Code, create the file below at .claude/skills/agent-safety-audit/SKILL.md in your project (in your code editor or terminal), then run it with /agent-safety-audit. Codex, Cursor and other agents can use the same text as a prompt. Anthropic documents the format in Claude Code skills. For tool-specific checks, see our pages for Claude Code, Cursor and Codex projects. New to skills? Our guide to agent skills covers how they load, with skills for code, design and email.

SKILL.md
---
name: agent-safety-audit
description: Audit this project and its development setup for the ways a coding agent can cause damage without any attacker. Audit only; change nothing until the owner approves.
---

# Agent safety audit

Audit first and change nothing. Never print secret values or use any credential: names and paths only.
Report each finding with file:line, why it's dangerous and the fix, ranked by how much damage it could do (top 3 first).
List anything outside the repository (accounts, tokens, settings, backups) as manual steps for the owner.
Wait for the owner's approval before applying any fix.

## 1. Get healthy
- Tests never touch real data; the test setup refuses a non-local database.
- Every change runs checks before it can merge; the live branch requires them.
- The project builds with no secrets present.
- Errors from the live app are reported somewhere a person reads.
- Public endpoints, and anything that costs money per call, are rate-limited.

## 2. Find the risks
- Test or dev settings pointing at production.
- Credentials the agent can read (files, shell, cloud CLIs, tokens).
- Deletes aimed by a variable, pattern or link.
- Infrastructure one command can destroy; backups the same token can delete.
- Push and publish rights with no gate.
- Tools that spend money or send messages without a cap.
- AI agents in CI reading untrusted input with secrets or write access.
- Unpinned MCP servers, hooks, plugins and skills; hidden Unicode in rule files.
- Auto-approve modes; safety nets defined as shell aliases.
- The project inside a cloud-synced folder.

## 3. Make the rules real
For every rule written only as text, propose the control that enforces it:
a hook that asks (and refuses in auto modes), a required check, a read-only role, a deny rule,
or a warning printed by the risky command itself. Name the safe command next to each rule.

## 4. Prove it
- Try to get round each new guard; ask a second agent to try too.
- Confirm each check actually runs (exit codes, not just silence).
- List the fixes only the owner can make in their accounts' settings.
09 · Where viberrr helps

An independent check, every time your agent ships

viberrr checks your live site from the outside: keys exposed in code anyone can download, open .env and .git files, security headers and HTTPS. Each finding comes with a fix your own agent can apply, and viberrr checks again to confirm it held. Start with the free launch readiness assessment, or check your live site from $9 a month. See exactly what we check, or connect your own agent.

Check my app
10 · Questions

AI coding agent safety: FAQ

Can an AI coding agent really delete production data?

Yes. It has happened in widely reported cases. The pattern is ordinary: the agent has access to a live database, often because development and production share one, and a step that looks like cleanup runs against real data. No attacker is involved, only access the agent shouldn't have had.

Isn't telling the agent "never touch production" enough?

No. Instructions in a rules file shape behaviour most of the time, but they don't enforce anything. The protection that holds is the one that makes the dangerous action impossible or forces a human decision: separate databases, read-only roles, protected branches and guards that ask first.

Should I stop using auto-approve modes?

Use them for low-risk work, inside a sandboxed project, with destructive actions blocked outright. The problem isn't speed. It's an agent approving its own irreversible actions. Guards must refuse in those modes, because an agent can answer its own prompt.

What's the single most important fix?

Separate development and test data from production, and keep production credentials out of the agent's reach. Most catastrophic agent incidents trace back to an agent that could reach live data it never needed.

Do these checks apply to Cursor, Codex and other tools, not just Claude Code?

Yes. The risks belong to the codebase and the setup, not to a particular agent. The audit prompt works with any agent that can read your project. The skill file format is Claude Code's, and the same text works as a prompt elsewhere.

How often should I run the audit?

After setting up a new project or tool, after giving an agent new access, and on a regular schedule, monthly at least. Setups drift: a token gets added, a test config changes, a new MCP server appears.

What if I'm not technical?

Paste the audit prompt into your agent and ask it to explain each finding in plain words before fixing anything. The fixes that need you (account settings, branch protection, backups) are listed as manual steps so you know exactly what to click.

This guide is general information, not a security audit of your project. Tool features and settings change; check your tools' own documentation. Linked coverage is from the sources named.