An AI coding agent is a fast editor with a terminal. It can rename a function, rewrite a migration, delete a test it considers unused, or commit a file you did not mean to share. Those are ordinary software mistakes, made at a speed that leaves less time for review.
This guide is a way to work with that speed without handing the agent your production system. It does not require a particular product.
Keep production credentials out of the agent’s reach
The highest-cost mistake is not a bad function. It is a tool that can reach production.
Do not put production database URLs, service-role keys, cloud admin tokens, or deployment tokens in the environment where the agent runs. Use a development database with data you can throw away. If a task needs production data, export a narrowed sample into that development database, and review the export for secrets and personal data before the agent sees it. Encrypt the export in transit and at rest, and restrict who can read the file. Use the production credential only to create the export, then remove it from the coding environment. If you keep the file, keep it somewhere independent of the production database, for a retention period you chose, and delete it when the task no longer needs it.
A local .env file is still a credential store. If the agent can read the workspace, it can read that file and can be asked to print it. Keep production values out of the workspace entirely, not only out of git.
Make the agent work on a branch
The default branch should not be the place an agent writes. Create a branch for the task, and look at the commits there. GitHub documents branch protection rules that apply to a branch name or a name pattern. Use them on the default branch so a change arrives through a pull request rather than a direct push. Read the current rule list in GitHub’s documentation before you depend on a specific checkbox. Rules change, and some rules have exceptions.
A branch is not a backup of the whole project. It is a way to see a change before it becomes the version you deploy.
Read the diff, not the chat summary
The chat will describe what the agent intended. The diff is what it did. Before you merge, read:
- Files you did not expect to change, especially lockfiles, CI workflows, and migrations.
- Deleted tests or loosened assertions.
- New dependencies, install scripts, and postinstall hooks.
- Changes to authentication, authorization, and row filters.
- Anything that prints, logs, or commits a secret.
Ask the agent to explain a hunk you do not understand, then check that explanation against the hunk. If the explanation and the diff disagree, believe the diff.
Treat database changes as a separate decision
Application code can often be reverted with another commit. A migration that drops a column or rewrites a table cannot. PostgreSQL’s backup documentation describes three different approaches, and they are not interchangeable: an SQL dump, a file-system copy, and continuous archiving. Pick one that you can restore, and take it before you run a destructive migration. The guide on production databases and AI coding agents goes further.
Do not let an agent apply a migration to a shared database because a local command happened to work.
Keep a copy the working tree cannot replace
A git commit on your laptop is one copy. If the laptop and the hosted repository are lost together, or if the damage was a bad commit that you pushed, you want a copy that is not the branch you are editing. That can be a mirror clone on another disk, a hosted backup you have restored at least once, or a database dump stored outside the database server. The point is independence: the copy should survive the failure of the thing it copies.
A copy you have never restored is an untested assumption. The difference is the subject of backups versus verified recovery.
A short working rule
Before you let an agent continue, you should be able to answer four questions:
- Which systems can this session actually change?
- Where will I read the diff before it is merged?
- If the database change is wrong, what copy will I restore, and where?
- What will I do if the agent has already run the command?
If you cannot answer the third question, do not run the migration.