Before You Let an AI Agent Touch Production: 7 Safeguards for Software Teams
By Obaid Tariq, Founder & Lead Engineer · Published · Updated
Obaid founded AI Dev Planner in 2022 and leads engineering on its client projects from Islamabad, Pakistan.
Seven safeguards control AI agents in production: a distinct identity per agent, least-privilege short-lived credentials, no access to production secrets, protected branches with human approval, required CI checks, a sandbox with limited network access, and audit logs with a tested kill switch and rollback. Enforce each one in the platform, not the prompt.
These are the same controls behind our AI development and production AI agents with guardrails and approvals services.
An AI coding agent should reach production only through the same controls you would demand of a new contractor, enforced by systems rather than by the agent's good behaviour. Give each agent its own identity, the narrowest short-lived credentials that do the job, no access to production secrets, a sandbox with limited network access, and a path to production that runs through protected branches, required CI checks and human approval. Log everything it does, and make sure someone can stop it and roll back quickly. Then raise its autonomy one step at a time, keeping a short list of actions it never takes alone.
What safeguards should be in place before an AI agent can touch production?
At minimum: a distinct identity per agent, least-privilege and short-lived credentials, no access to production secrets, protected branches with required human approval, CI checks that cannot be skipped, a sandbox with restricted network and no production database by default, and audit logs with a working stop switch and rollback. Each of these should be enforced by the platform the agent runs on, not by instructions in a prompt, because an agent can misread instructions or be manipulated into ignoring them.
Why this matters now
Agents are no longer only suggesting code in an editor. They open pull requests, run shell commands, call tools through the Model Context Protocol (MCP) and sometimes deploy. Release activity reflects that: SparkPulse's software development trends page, updated 20 October 2026, lists MCP, agent governance, agent identity and durable execution among the month's themes. SparkPulse ranks products by how often they ship updates according to changelogs and release feeds, so treat this as a signal of where vendors are building, not a measure of how many teams have adopted these tools.
The risk has a name. The OWASP Top 10 for LLM Applications calls it Excessive Agency: an AI system with access to tools takes damaging actions because its output was unexpected, ambiguous or manipulated, for example through prompt injection or a compromised extension. OWASP traces it to three root causes: excessive functionality, excessive permissions and excessive autonomy. The seven safeguards below map onto those three causes. If you are setting up an agent for the first time (context files, skills, connecting MCP servers), start with our guide to an AI coding agent workflow and come back here before it gets anywhere near production.
1. A distinct identity for every agent
Do not run agents on a developer's personal account, a shared "bot" login or a long-lived personal token copied into a config file. If the agent acts as you, your logs cannot tell your actions from its actions, and a leaked credential carries all of your access. Give each agent, or each agent role, its own identity.
- On GitHub, prefer a GitHub App for automation. GitHub's documentation says personal access tokens are for acting on your own behalf and recommends a GitHub App for organisation access, long-lived integrations and automations. Apps use fine-grained permissions, the installer chooses which repositories they can reach, they are not tied to a user account (so they keep working if that person leaves), and they use short-lived tokens.
- Use the agent's own identity where the vendor provides one. GitHub describes Copilot's cloud agent opening pull requests under its own app identity, which keeps its work attributable and separate from the person who asked for it.
- One identity per environment. An agent that works in staging should not hold a credential that also works in production.
2. Least privilege, scoped tokens and short-lived credentials
Grant only the permissions the task needs, on only the resources it needs, for only as long as it needs them. OWASP's mitigations for Excessive Agency include limiting each tool to the functions it needs, avoiding open-ended tools such as arbitrary shell commands in favour of narrow ones, and granting the minimum permissions on downstream systems, such as read-only database access.
- Fine-grained over classic tokens. GitHub recommends fine-grained personal access tokens where possible. They can be limited to specific repositories and specific permissions, whereas a classic token can reach every repository you can. Fine-grained tokens default to a 30-day expiry; set the shortest lifetime that works and, for organisations, a maximum lifetime policy.
- Scope MCP connections too. The MCP security best practices warn against wildcard or omnibus scopes such as
*orfull-accessand recommend starting with a minimal scope set and elevating only when a privileged operation is first attempted. They also say an MCP server must not accept tokens that were not issued for that server, a pattern the specification calls token passthrough. - Prefer read-only by default. Most agent tasks need to read far more than they need to write. Make write access the exception you grant deliberately.
3. Secret isolation
An agent should never see a production secret. Anything in its context can end up in a log, a commit, a pull request description or a request to an external service, and an agent manipulated by prompt injection may try to send it somewhere deliberately.
- Keep production secrets in a vault or your hosting platform's secret store, injected at runtime into the deployed app, never into the agent's working environment.
- Block the agent from reading local secret files. In Claude Code, a deny rule such as
Read(./.env)stops the built-in file tools from reading that file. Anthropic's documentation is explicit that these rules do not stop an arbitrary script from opening the file, and points to the sandbox for operating-system-level enforcement. - Scrub the environment. Claude Code's sandbox documentation notes that sandboxed commands inherit environment variables by default, including any secrets in them. Launch agents from a clean environment.
- Turn on push protection. GitHub's push protection blocks hardcoded secrets in command-line pushes, web commits, file uploads and REST API requests. By default anyone with write access can bypass a block by giving a reason, which is logged; use delegated bypass so an agent cannot wave its own block through.
4. Branch protection and required human approval
The agent's path to production should be the same as everyone else's: a branch, a pull request, review and merge. GitHub's protected branches can require a number of approving reviews, dismiss stale approvals when new commits arrive, require approval of the most recent push from someone other than the pusher, require code owner review, restrict who can push and block force pushes. Enable "do not allow bypassing" so administrators, and any tokens acting as administrators, are bound by the same rules.
Copilot's cloud agent is a useful reference design. According to GitHub, it pushes only to a single branch (a new copilot/ branch unless it was asked to work on an existing pull request), the person who asked for the pull request cannot approve it, and the agent cannot mark its own pull request ready for review, approve it or merge it. Whatever agent you use, aim for the same properties.
5. CI checks as non-negotiable gates
Required status checks turn "the agent says the tests pass" into "the tests passed on a clean runner". Make type checks, linting, tests, the build, dependency scanning and secret scanning required for merge, and require the branch to be up to date before merging. Two agent-specific points:
- Protect the pipeline definition itself. An agent that can edit workflow files can weaken the checks that judge its work. Put workflow and deployment configuration under code owners and require a human reviewer for changes to them.
- Don't run agent-authored workflows automatically. GitHub says workflows on Copilot's pull requests don't run until someone with write access approves them. That stops a pull request from using CI to reach secrets or other systems before a person has looked at it.
6. Sandboxing
Run agents where a mistake is cheap: a container, a virtual machine or a disposable cloud environment, with a separate Git worktree or clone per task so parallel agents cannot interfere with each other. Anthropic's documentation says Claude Code's permission-skipping mode should only be used in isolated environments such as containers or VMs, and lets organisations disable that mode through managed settings.
- Limit network egress to an allowlist. Claude Code's sandbox routes connections through a proxy that checks each host against allowed domains, which start empty. The MCP security guidance recommends egress proxies and blocking private and link-local address ranges, including cloud metadata endpoints, which can expose credentials.
- Know what sits outside the sandbox. Claude Code's sandbox wraps shell commands only. Its documentation says built-in file and web tools follow permission rules instead, and that hooks and local MCP servers run with your full access. To put everything behind one boundary, run the whole agent inside a container or VM.
- No production database by default. Give agents a local or seeded database. If a task truly needs production data, use a read-only replica or a masked copy, granted for that task and revoked afterwards.
- Vet local MCP servers. The MCP guidance notes that local servers run with the client's privileges and recommends sandboxing them with minimal default access and showing the exact start-up command before approving one.
7. Audit logging, a kill switch and rollback
OWASP notes that logging and monitoring do not prevent Excessive Agency but do limit the damage. You need to know what the agent did, stop it quickly, and undo what it changed.
- Log every consequential action with the agent identity, the human who started the task, the tool called, its arguments with secrets redacted, the result and a timestamp. Ship logs somewhere the agent cannot edit or delete.
- A kill switch you have tested. Revoke or suspend the agent's credentials, for example by suspending its GitHub App installation or revoking its tokens, stop its runner, and disable any scheduled triggers. Write the steps down and rehearse them.
- Rollback. Every agent change should be a revertible commit or deployment. Know how your hosting platform returns to a previous deployment, and keep database migrations backwards compatible so a code rollback does not strand data.
For incident handling more broadly, see monitoring, backups and incidents. If you need customer-facing audit logs inside a multi-tenant product, that is a different problem covered in our guide to multi-tenant SaaS architecture.
The seven safeguards at a glance
| Safeguard | Risk it addresses | Minimum setup | How to verify it's working |
|---|---|---|---|
| Distinct agent identity | Agent actions indistinguishable from a person's; a leak exposes a human's full access | GitHub App or dedicated service account per agent and environment | Pick a recent agent commit or PR and confirm the logs attribute it to the agent, not a person |
| Least privilege and short-lived credentials | A manipulated or buggy agent uses access it never needed | Fine-grained, repository-scoped, expiring tokens; read-only by default; minimal MCP scopes | Ask the agent to act on a repository or resource outside its scope; the request should be refused |
| Secret isolation | Production secrets leak into prompts, logs, commits or outbound requests | Secrets in a vault, not the agent environment; deny reads of secret files; push protection with delegated bypass | Push a known test secret from the agent's environment; it should be blocked and alerted |
| Branch protection and human approval | Unreviewed changes reach production | Protected main with required approval, approval of latest push by someone else, no bypass | Try to push directly to main and to merge without approval using the agent's credentials; both should fail |
| CI as a gate | Broken or insecure code merges because the agent claimed it was fine | Required status checks; workflow files under code owners; manual approval for agent-triggered workflows | Open an agent PR with a deliberately failing test; merge should be blocked |
| Sandboxing | Damage to the host, other projects, internal networks or production data | Container or VM per task, egress allowlist, no production database credentials | From inside the sandbox, try to reach a domain not on the allowlist and the production database; both should fail |
| Audit log, kill switch and rollback | Nobody can tell what happened, stop it or undo it | Tamper-resistant action logs, documented credential revocation, revertible deploys | Run a drill: revoke the agent mid-task and roll back its last deploy, and time how long it takes |
These safeguards are about the agents your team runs. Defending your public web app against outside attackers who use AI tools is a separate topic, covered in hardening a web app against AI agent attacks, and protecting AI features inside your own product from prompt injection is part of our secure AI development work.
How much autonomy should an AI coding agent have, and what should it never do on its own?
Start every agent at the lowest level, suggesting changes for a person to apply, and move it up one level at a time only when the safeguards for that level are in place and its track record justifies it. Most teams should stop at agent-authored pull requests with human review, and allow auto-merge only for narrow, low-risk, well-tested change types. Some actions, such as production deploys, data deletion, permission changes and anything touching money or secrets, should always need a person.
Autonomy is a dial, not a switch
OWASP lists excessive autonomy, an application that does not independently verify or approve high-impact actions, as one of the three root causes of Excessive Agency, and recommends human approval for high-impact actions. The NIST AI Risk Management Framework, a voluntary framework organised around the functions Govern, Map, Measure and Manage, takes a similar view: decide in advance who is accountable and what level of risk you accept, rather than discovering it after an incident. In practice that means writing down how much each agent may do, per type of task.
The autonomy ladder
| Level | What the agent can do | Who approves | Safeguards required before this level |
|---|---|---|---|
| 0. Suggest only | Read code and propose changes or plans; a person applies them | The person applying the change | Separate identity, read-only access, no secrets in context |
| 1. Edit locally, ask before acting | Edit files and run commands in a sandbox, asking before risky steps | The developer, step by step | Sandbox or container, egress allowlist, deny rules for secret files |
| 2. Pull request with review | Push to its own branch and open a PR; cannot approve or merge | A human reviewer who did not start the task | All seven safeguards: protected main, required checks, audit log, kill switch |
| 3. Auto-merge low-risk changes | Merge narrowly defined changes automatically when every check passes | A policy agreed in advance, with spot checks | Strong test coverage on affected paths, path-based rules, fast rollback, monitoring and alerts |
| Never autonomous | See the list below | Always a named person | Not applicable: these stay manual |
In our view, level 2 is the right default for most product teams today. It keeps most of the speed benefit while keeping a person accountable for every merge. How much of that agent-written code is ready to ship is a judgement call we discuss in how much AI-generated code should ship.
What counts as low risk for auto-merge
If you do allow level 3, define it by file paths and change types that your branch rules can enforce, not by the agent's own judgement of risk. Reasonable candidates:
- Patch-level dependency updates that pass the full test suite, ideally from a dedicated tool such as Dependabot rather than a general-purpose agent.
- Documentation, comments and typo fixes outside code paths.
- Formatting and lint autofixes with no behavioural change.
- Test-only changes that add coverage without changing application code.
Actions an agent should never take on its own
- Deploying to production or promoting a release.
- Running database migrations against production, or deleting or bulk-updating production data.
- Changing authentication, authorisation, roles or permission logic.
- Creating, reading, rotating or deleting secrets and credentials.
- Editing CI/CD workflows, branch protection, repository settings or its own permissions.
- Anything that moves money: payment configuration, refunds, pricing or billing changes.
- Changing infrastructure, DNS, networking or access policies.
- Sending messages to customers or third parties, or publishing public content.
- Installing new MCP servers, plugins or dependencies from sources nobody has reviewed.
- Approving or merging its own pull request, or disabling a failing check.
Moving up a level, and back down
- Promote on evidence. Review a meaningful sample of an agent's merged work and any reverts before raising its level, and raise it for one task type at a time.
- Demote automatically. A revert, a security finding or a failed rollback drill should drop the agent back a level until the cause is understood.
- Review quarterly. Agent tools change quickly; vendors add capabilities and defaults shift. Re-run the verification tests from the safeguards table whenever you upgrade the tool or change its configuration.
Choosing which agent to run is a separate decision, covered in our comparison of AI coding agents. Whichever you pick, the ladder and the never list stay the same.
What makes an AI agent production-ready?
An AI agent is production-ready when it does one defined workflow, can only use the tools and data that workflow needs, passes an agreed eval set of normal, edge and adversarial cases, sends risky actions to a person for approval, fails safely and visibly, logs every step, is monitored after launch, and has a known running cost per task. A demo proves the model can do the task once; production-readiness proves the system around it holds up every day.
Why so many agents stall between pilot and production
Deloitte's Tech Trends 2026 reports that only 11% of organizations have agents in production, despite 38% piloting them. In our experience the gap is rarely the model. It is the work around it: deciding exactly what the agent is for, what it may touch, how anyone knows it works, and what happens when it does not. The safeguards above apply to agents that write code; the checklist below applies to agents that run business workflows such as triaging tickets, processing documents or updating a CRM.
The production-readiness checklist
| Check | What "ready" looks like | Red flag |
|---|---|---|
| Defined workflow outcome | One workflow, a written definition of "done" and a business metric it should move | "Automate our operations" with no single workflow named |
| Systems and data permissions | A list of every system and field the agent reads or writes, with least-privilege, separate credentials for each tool | One admin API key shared across every tool |
| Human approval points | Written list of actions it takes alone, actions that need a person, and actions that are blocked | Approval rules that live only in the prompt |
| Evaluation | An eval set built from real cases, including edge and adversarial ones, with pass thresholds for task success, escalation accuracy and cost per task | Accuracy judged by trying a few examples by hand |
| Failure handling | Step, time and spend limits; retries with backoff; staged writes that roll back; escalation with full context when unsure | Unlimited retries, or errors that disappear silently |
| Logging and audit | Every input, tool call, result and approval logged where the agent cannot edit it | Logs that only show the final answer |
| Monitoring after launch | Success rate, escalations, cost and incidents tracked, with the eval set re-run when the model, data or tools change | No owner for the agent once it ships |
| Operating cost | Cost per task measured in the prototype, and a budget for model usage, hosting and maintenance | Only the build has been priced |
Secure AI agent architecture: permissions, logging, evaluation and human approval
The same rule from the safeguards above applies: enforce controls outside the model. In practice a secure agent architecture has four layers.
- Permissions. Each tool is narrow and typed, validated against a schema before it runs, and backed by credentials scoped to that tool. Read and write tools are separate, and anything the agent retrieves is filtered by what the requesting user is allowed to see. This maps to OWASP's mitigations for Excessive Agency.
- Untrusted input. Emails, documents and web pages are treated as data, never as instructions, so text hidden in them cannot widen the agent's permissions (OWASP LLM01 Prompt Injection).
- Human approval. High-impact actions, such as payments, external messages, deletions and permission changes, pause in a review queue showing the exact change, and a person approves, edits or rejects it. New agents start in shadow or approve-everything mode, and autonomy widens one action type at a time as the eval results justify it.
- Logging and evaluation. Every step is logged with the agent identity, the user who started the task, the tool, its arguments with secrets redacted, the result and any approval. The eval set runs on every change, so a model upgrade that lowers accuracy is caught before customers see it.
For the architecture patterns behind this (staged diffs, approval gates and token circuit breakers), see AI agent architecture for B2B operations. For how agents differ from chatbots and traditional workflow automation, and what a production build costs, see our AI agent development services.
Frequently asked questions
What is excessive agency in AI agents?
Should an AI coding agent use my GitHub account?
Can an AI agent merge its own pull requests?
Is a prompt instruction enough to stop an agent doing something dangerous?
How do you know an AI agent is ready for production?
What is the quickest way to stop a misbehaving AI agent?
Sources
- Deloitte Insights: Tech Trends 2026 — Only 11% of organizations have agents in production, despite 38% piloting them (checked 2 December 2026). Accessed 20 October 2026.
- OWASP GenAI Security Project: LLM01:2025 Prompt Injection — Prompt injection through untrusted inputs; mitigations include separating and marking external content and least-privilege access. Accessed 20 October 2026.
- SparkPulse: Software development trends — Lists MCP, agent governance, agent identity and durable execution among current themes; ranks products by release activity from changelogs and release feeds, not adoption. Accessed 20 October 2026.
- OWASP GenAI Security Project: LLM06:2025 Excessive Agency — Definition of Excessive Agency; root causes of excessive functionality, permissions and autonomy; mitigations including minimal tools and permissions, human approval for high-impact actions, authorisation in downstream systems; logging limits damage but does not prevent it. Accessed 20 October 2026.
- NIST: AI Risk Management Framework — AI RMF is a voluntary framework released in January 2023; Generative AI Profile (NIST-AI-600-1) released July 2024. Accessed 20 October 2026.
- GitHub Docs: Managing your personal access tokens — Fine-grained tokens scoped to specific repositories and permissions; 30-day default expiry; GitHub recommends fine-grained tokens and a GitHub App for organisation access and automations. Accessed 20 October 2026.
- GitHub Docs: Deciding when to build a GitHub App — GitHub Apps use fine-grained permissions, installer-selected repositories and short-lived tokens, and are not tied to a user account. Accessed 20 October 2026.
- GitHub Docs: About protected branches — Required reviews, dismissing stale approvals, approval of the most recent push by someone else, code owner review, required status checks, restricting pushes, blocking force pushes and disallowing bypass. Accessed 20 October 2026.
- GitHub Docs: About push protection — Push protection blocks hardcoded secrets across pushes, web commits, uploads and API requests; bypass with a reason by default; delegated bypass. Accessed 20 October 2026.
- GitHub Docs: Risks and mitigations for GitHub Copilot cloud agent — Copilot pushes to a single copilot/ branch; requester cannot approve; agent cannot mark ready, approve or merge; workflows need approval before running; restricted internet access. Accessed 20 October 2026.
- Model Context Protocol: Security Best Practices (2025-11-25) — Token passthrough forbidden; scope minimisation and avoiding wildcard scopes; egress proxies and blocking private ranges; sandboxing and consent for local MCP servers. Accessed 20 October 2026.
- Claude Code documentation: Configure permissions and sandboxing — Read deny rules such as Read(./.env) and their limits; bypass mode only in isolated containers or VMs; disabling bypass mode via managed settings. The linked sandboxing page (code.claude.com/docs/en/sandboxing) covers the egress allowlist, inherited environment variables and what runs outside the sandbox. Accessed 20 October 2026.
Recommendations without a source are AI Dev Planner’s own engineering opinion. Platform features and prices change; check the linked pages for the current position. Found an error? See our corrections policy.
Related guides
- AI, Vibe Coding & the Future of SaaSProduction AI Coding Agent Workflow: Claude Code, Cursor & Spec-Driven QAA CTO and engineering-leader guide to Claude Code, Cursor, MCP permissions, Playwright E2E verification loops, and preventing AI technical debt.
- Operations, Security & ComplianceHow to Harden Web Apps & AI Agents Against Prompt Injection and Automated AttacksOWASP LLM Top 10 defenses for US engineering teams: prompt injection mitigation, MCP OAuth sandboxing, PII redaction, and Zod schema validation.
- Career, Learning & Web Development FundamentalsModern Web Development Workflow (2026): Our AI-Augmented SDLC from PRD to ProductionSpec-driven PRDs, Cursor/Claude Code implementation, Playwright E2E verification, Vercel preview URLs per PR, and zero-downtime CI/CD.
- Operations, Security & CompliancePost-Launch SaaS Engineering Operations: 99.9% SLAs, Incident Response & Cloud FinOps99.9% SLA reliability, incident response runbooks, 3-2-1 backup restore drills, and AWS Cloud FinOps for US founders scaling past MVP.
- AI, Vibe Coding & the Future of SaaSAI Agent Architecture for B2B Ops: Guardrails, Approvals & Cost ControlAutonomous B2B workflows that won't break production: staged diff previews, approval gates, state rollback, and token budgets — the four things that stand between an agent and a very bad day.
Browse all 139 questions in the SaaS & web development guide.
Want agents in your workflow without handing them the keys?
We set up AI coding agents behind separate identities, scoped credentials, sandboxes, protected branches and required checks, so your team gets the speed with a person accountable for every release. Tell us how your team works today and we will suggest a safe starting level.