Insights
How do you keep AI agents away from production?
By Rare Agentics engineering teamLast updated First published 8 minute read
You keep AI agents away from production by making it impossible for them to reach it, not by telling them not to. Agents work in separate environments with credentials that cannot merge, deploy or touch live systems, a person approves every release and every consequential action, and every agent action is logged. You keep the speed because agents still do the volume of the work; only the last step belongs to a person.
Why is telling an agent not to touch production not enough?
Many teams that use AI agents protect production with instructions alone. The prompt says "never run migrations against the live database" or "do not push to main". That is not a control. It is a request.
Agents follow instructions most of the time. They also misread context, act on instructions hidden in a file or a web page (prompt injection), and occasionally do the wrong thing with complete confidence. If the agent holds a credential that can drop a production table, the only thing standing between you and a bad afternoon is the agent choosing not to.
The rule we work to is simple: if an agent should never do something, it should not have the access to do it. Merging, deploying and touching production should be impossible for an agent by construction, not merely disabled. "Disabled" means a setting someone can flip, a flag a future prompt can talk its way past, or a permission that quietly comes back when a token is reissued. "By construction" means the credentials the agent holds simply cannot do it.
This applies to AI coding agents writing your software and to agents running inside the business, such as one that drafts payment runs or updates client records. The mechanics differ; the principle does not.
How should environments be separated when agents write code?
Start with three separate places, and be strict about which credentials exist in each.
The agent's workspace. Each agent works in its own separate workspace: its own branch, its own copy of the code, its own throwaway database seeded with test data. It can build, run tests and break things freely. Nothing it does there can reach a real customer.
Staging. A copy of production that is as close as you can make it, with its own database and its own keys. Changes land here after review, and this is where a person checks behaviour before release. Agents may read test results from staging; they should not hold credentials that can change it outside the normal review path.
Production. Live systems, live data, live keys. Only named people hold the credentials that deploy here, and the release process is controlled by an engineer, not an agent.
Four traps to look for:
- Shared secrets. If the same API key or database password works in staging and production, you do not have two environments. You have one with two names.
- Production data in test environments. Copying the live database into an agent's workspace "to make the tests realistic" puts real personal data in front of a tool that may send it to a model provider. Use seeded or masked data.
- Long-lived tokens on developer machines. An agent running locally can see whatever the developer's machine can see. If that includes a production token in an environment file, the agent has production access whether you meant it to or not.
- Tools and connectors with more reach than the task. A connector to your cloud console, database or email gives the agent whatever that connector's credentials can do. Scope each one to the task.
What access should an AI coding agent actually have?
Write it down as a table and enforce every row with permissions, not prompts. Here is the split we use.
| Action | Agent | Person |
|---|---|---|
| Read the codebase and documentation | Yes | Yes |
| Write code in its own workspace and branch | Yes | Yes |
| Run tests against seeded test data | Yes | Yes |
| Open a pull request for review | Yes | Yes |
| Review and approve a pull request | No | Yes |
| Merge to the main branch | No | Yes, after review |
| Deploy to staging or production | No | Yes, a named engineer |
| Read or write production data | No | Only where the role requires it |
| Change cloud, billing or access settings | No | Yes, a named owner |
On GitHub and similar platforms most of this is ordinary branch protection: required reviews, no direct pushes to the main branch, and deploy credentials held only by the release pipeline and the people who run it. The point is to make sure the agent's token is scoped to match the table, and that nobody gives it a broader one because it was quicker.
Two gaps catch people out. An admin token can bypass branch protection, so the agent's token must never hold admin rights, and the rules should apply to administrators too. And an agent that can push a branch may be able to edit the workflow files that run with your deploy secrets, so keep production secrets in a protected environment that needs a named reviewer, available only to the protected branch.
None of this slows the work much. Agents still write the code, run the tests and prepare the change. What a person adds is the review and the release, which is where judgement matters most.
Where should approval gates sit?
An approval gate is a point where work stops until a named person says yes. Put them where a mistake is expensive or hard to undo, and nowhere else. Too many gates and people approve without reading; too few and the gates that matter are missing.
For software, the gates that earn their place are:
- Before merge. Every change is reviewed by a person before it is merged.
- Before release. A person signs off every release to production.
- Before any change to infrastructure or access. New cloud permissions, new keys, new outside services.
For agents working inside the business, the gates sit on actions rather than code. Payments, deleting records, changes to customer records and releases to production should always need a person. For example, an agent can read supplier invoices, match each to its purchase order and draft the payment run, but the payment itself waits for someone to approve it.
A gate is only as good as the information in front of the approver. The request should show what the agent wants to do, what it based that on and what will change. "Approve action 4471?" is not a gate. It is a button.
What should be logged for every agent action?
If something goes wrong, you need to answer four questions quickly: which agent acted, the sources it used, what it did, and who approved it. Record all four for every action, not only the ones that failed.
In practice that means:
- The agent. Which agent, and which version of its instructions and tools.
- The sources. The documents, records or files it read to reach its answer.
- The action. What it did or proposed, with the before and after where something changed.
- The approval. Who approved it and when, or a note that it acted within bounds that did not need approval.
One more rule belongs here. An answer its sources do not support should go to a person instead of being sent. If an agent drafting a customer reply cannot point to the document that backs its claim, the reply should be routed for review rather than going out on confidence alone.
Keep the log somewhere the agent cannot edit. A record the actor can rewrite is not much of a record.
How do autonomy levels work, and when should they widen?
Not every action needs a person every time. The trick is to decide, per task, how much the agent may do on its own, and to widen that only on evidence. We use five levels.
| Level | What happens | When to use it |
|---|---|---|
| Observe | The agent records what it would have done and takes no action | Before go-live, to measure accuracy on real cases |
| Suggest | The agent proposes, a person acts | A new agent, or a task that has changed |
| Act with approval | The agent prepares the action and carries it out once a person approves | Anything consequential |
| Act and report | The agent acts and tells a person what it did | Routine, reversible steps with a track record |
| Act without sign-off | The agent acts within its bounds without reporting each step, though every action is still logged | Low-risk, high-volume work where checking each step adds nothing |
Three rules make this work:
- Start low. A new agent begins at Observe or Suggest, whatever the demo looked like.
- Widen one level at a time. Move up only when the log shows the agent getting it right at the current level, and only when the business owner agrees.
- Some actions never move. Payments, deletions, changes to customer records and production releases stay at Act with approval or below, permanently.
For AI coding agents, the equivalent is simple: they can act freely inside their own workspace and never act on production.
How do you keep the speed?
The worry with all of this is that controls cancel out the reason for using agents. They do not, provided the controls sit in the right places.
Agents are fast at the volume of the work: reading, drafting, writing code, running tests, checking results, preparing changes. None of that needs production access. Agents can build in parallel, each in its own separate workspace, while senior engineers review and decide. The slow, careful step is the one that should be slow and careful: a person deciding that a change is ready for real customers.
What does slow teams down is the opposite: an agent with too much access causes an incident, and everyone loses a week to recovery and a month to nervousness.
What should you ask a supplier who uses AI agents?
If an agency or freelancer builds your software with AI agents, as many now do, ask:
- Can your agents merge, deploy or reach our production systems? How is that prevented, technically?
- Are our staging and production credentials separate, and who holds the production ones?
- Does a person review every change before it is merged, and sign off every release?
- Is any of our production data used in agent workspaces or sent to model providers?
- Can you show us the log of what your agents did on our code?
Vague answers, or "the agents are instructed not to", tell you what you need to know. Our list of questions to ask a software development company covers the rest of the conversation. If you already have software built quickly with AI tools and are not sure how it was put together, a security review for AI-built apps will find the access problems before a customer does. Our guide to making an AI-built app safe before launch covers the common gaps. And if you are deciding where agents should work in the business at all, start with what an agent readiness review covers.
How Rare Agentics can help
Every build we do works this way: agents build in separate workspaces, merging, deploying and touching production are impossible for them by construction, and a named engineer ships every release. Our custom AI agents apply the same controls inside your business, with every action logged against the agent that took it and the person who approved it. If you want your current setup checked or a new agent built properly, talk to us.