Why agents should never touch production rows
AI agents should never touch production database rows to prevent privacy breaches, accidental data destruction, and unrecoverable user state changes.
On this page 8 sections
AI agents should never touch production database rows because exposing live customer records risks privacy violations, prompt injection exploits, and accidental data deletion. Autonomous coding agents need access to database schemas, column definitions, and migration ledgers to build features, but they do not need live user data to test queries. Providing agents with a sanitized development branch rather than live production tables keeps live data isolated while letting tools build and verify code safely.
When an agent writes code or inspects database state, giving it direct credentials to a live Postgres instance creates immediate liabilities. The safest architecture isolates the agent inside a dedicated development environment where every table exists, schema migrations apply cleanly, and zero customer rows are exposed.
What risks appear when agents touch production data?
Giving an agent access to production rows introduces several failure modes that traditional software workflows avoid:
- Data loss from unconstrained statements. An agent generating raw SQL or running ORM commands can execute an unintended
DROP TABLE,TRUNCATE, or unindexed bulkUPDATEwithout aWHEREclause. - Exposure of private user records. Live tables contain personal emails, auth sessions, and billing history. Any prompt injection, errant log statement, or context dump can echo sensitive user rows into external model context windows or telemetry streams.
- Poisoned migration ledgers. If an agent attempts to reconcile a migration by editing records directly in live tracking tables, migration ledgers drift out of sync, making future deploys unreliable.
A sound development pipeline treats production data as strictly off-limits to automated assistants. To see how credential exposure affects your setup, read should an AI agent hold production secrets?.
How the development copy protects live rows
thelastapi assigns two distinct environments to every project: production and development. The production database holds the real application data. The development copy is an automated branch that duplicates the exact production schema—tables, views, indexes, and constraints—with none of its rows.
Every table in the development copy is emptied, including user records and active sessions. Crucially, migration ledgers such as Drizzle's and Prisma's are preserved so running migrations in development will not attempt to re-apply historic schema changes twice.
When an engineer or an agent runs vibiz dev, the CLI provisions or points to this development branch:
vibiz dev # DATABASE_URL for the development branch, written to .env.development.local
npx drizzle-kit migrate # runs your schema migrations safely against developmentThe app's local code connects using standard Postgres drivers without exposing production credentials:
import postgres from 'postgres';
const sql = postgres(process.env.DATABASE_URL!);
const rows = await sql`select id, email from users limit 10`;
console.log(rows);Because the development branch has no production rows, an agent can insert mock data, run test queries, drop test tables, or trigger errors without affecting real customers. If an agent pollutes the branch or corrupts its test data, you can reset the entire development environment instantly:
vibiz dev --resetThe next call to vibiz dev provisions a clean branch mirroring the current production schema once again. You can read more about this workflow in a development database branch agents cannot break.
What agents can and cannot do
Access control in thelastapi separates owner capabilities from automated agent workflows. API keys created for agents are assigned a Limited access profile (access: agent). A Limited key cannot view the production DATABASE_URL, cannot download production row exports, and cannot run raw queries against production data.
Here is how permissions differ across environments:
| Action | Development copy | Production database |
|---|---|---|
DATABASE_URL availability | Yes (via vibiz dev) | No (owners only) |
Read-only SQL view (/database/query) | Yes | No (403 owner_only) |
| List schemas and tables | Yes | No (403 owner_only) |
| Direct writes via Postgres client | Yes (against dev URL) | Never for Limited keys |
| Database exports | Full SQL export allowed | No (403 owner_only) |
When working through an agent or a tool running with a Limited key, the agent inspects schemas using the read-only database query endpoint:
curl "https://thelastapi.dev/v1/projects/prj_123/database?env=development" \
-H "Authorization: Bearer $VIBIZ_API_KEY"This returns schemas, tables, and row estimates. To inspect columns or run specific verification statements, the agent sends SQL to the read view:
curl https://thelastapi.dev/v1/projects/prj_123/database/query \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H 'content-type: application/json' \
-d '{"sql":"select table_name from information_schema.tables where table_schema = '\''public'\''","env":"development"}'The read view enforces strict safety rails: it accepts only a single SELECT, WITH, TABLE, VALUES, EXPLAIN, or SHOW statement up to 20,000 characters, executes with a 5-second timeout, and returns at most 500 rows (flagging truncated: true if more exist). Any query that attempts to write inside the read view fails with 400 invalid_request.
For a broader look at managing isolated databases across teams, see serverless Postgres for side projects: one database per project and the official Database documentation.
Managing database migrations safely
Schema changes present another risk area. When an agent modifies application models, it must test migrations against real database syntax, constraints, and data types before anything reaches production.
Because the development copy maintains identical table definitions and the schema migration ledger, an agent can generate migration files, test them locally against DATABASE_URL, and verify that table definitions reflect the intended state. If a migration fails due to bad syntax or a broken foreign key, only the development branch experiences the failure.
Review the step-by-step migration pattern in run database migrations safely with an AI agent.
How permission boundaries work when an agent asks for more
If an agent holding a Limited key attempts to access production database rows or call a protected endpoint, the API immediately blocks the request with a 403 forbidden error:
{
"error": "forbidden",
"details": {
"reason": "owner_only",
"permission": "database.production:read",
"grant_url": "https://thelastapi.dev/keys/key_123/allow?permission=database.production:read",
"console_url": "https://thelastapi.dev/projects/prj_123/settings",
"key_id": "key_123"
}
}The API does not simply reject the call; it returns structured fields explaining what is missing:
details.permission: the specific permission required (e.g.,database.production:read).details.grant_url: a unique URL where the project owner can review the request and explicitly allow that permission, assign theread_allpreset, or decline.details.console_url: the console location where an owner can inspect key settings manually.
The agent presents details.grant_url to the user and halts. Once the human owner grants the permission, the agent can retry. A Limited key cannot elevate its own permissions or create other keys; changes require an owner key or explicit console approval.
You can also assign single permissions or granular roles using the CLI:
# Inspect permissions
vibiz keys permissions
# Grant only production read access to a specific reporting key
vibiz keys access key_123 allow database.production:read
# Create a key with the read-all preset
vibiz keys create reporter --read-allFor more details on key scoping, review the Keys and environments guide.
What happens during database exports?
Backups and migrations should never leak live customer records to unauthorized tools. Project exports via vibiz export bundle the application code, the database, and an environment guide. When run with a Limited key, the export defaults strictly to the development environment.
# Exports the project's development database, code, and guide
vibiz export --db --csvA Limited key attempting to pass --env production for a database export receives a 403 owner_only error. Only an owner holding a full-access key can export the production database snapshot (<slug>-production-database.sql.gz). Even then, production secrets and database passwords are excluded from the main zip file; they must be downloaded independently using vibiz export --secrets or via the console's explicit confirmation modal. Check the Export documentation for complete archive specifications.
Next steps
To build applications with agents without exposing live data, initialize your project with isolated resources:
vibiz init acme-app --resources database,auth
vibiz devInspect your development schema with vibiz dev, verify that your agent uses a Limited key, and keep live production rows guarded behind owner-level controls.
Frequently asked questions
Can an AI agent read production rows if it uses a Limited API key?
No, Limited keys receive a 403 owner_only error when attempting to query production rows or read the production DATABASE_URL. To view production records, a project owner must explicitly grant the database.production:read permission via the console or CLI.
How does the development database branch differ from the production database?
The development branch contains all of production's schemas, tables, indexes, views, and migration ledgers, but every row is emptied. This ensures an agent can test queries and migrations against the real database structure without viewing or breaking live customer data.
What happens if an agent corrupts or breaks the development database branch?
You can discard the damaged branch by running `vibiz dev --reset`. The next time you run `vibiz dev`, the platform provisions a clean development branch mirrored directly from production schemas with empty tables.
How much does a ready Postgres database cost on thelastapi?
Usage records each ready database at an estimated $0.02 a day of cost, billed with the default margin (+20% today) as billed_usd while final pricing is being determined.