Skip to main content
Operations, Security & Compliance

Before You Let an AI Agent Touch Production: 7 Safeguards for Software Teams

By Obaid Tariq, Founder & Lead Engineer · Published

The short answer

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 * or full-access and 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

Seven AI agent safeguards: the risk each addresses, a minimum setup and how to check it works
SafeguardRisk it addressesMinimum setupHow to verify it's working
Distinct agent identityAgent actions indistinguishable from a person's; a leak exposes a human's full accessGitHub App or dedicated service account per agent and environmentPick a recent agent commit or PR and confirm the logs attribute it to the agent, not a person
Least privilege and short-lived credentialsA manipulated or buggy agent uses access it never neededFine-grained, repository-scoped, expiring tokens; read-only by default; minimal MCP scopesAsk the agent to act on a repository or resource outside its scope; the request should be refused
Secret isolationProduction secrets leak into prompts, logs, commits or outbound requestsSecrets in a vault, not the agent environment; deny reads of secret files; push protection with delegated bypassPush a known test secret from the agent's environment; it should be blocked and alerted
Branch protection and human approvalUnreviewed changes reach productionProtected main with required approval, approval of latest push by someone else, no bypassTry to push directly to main and to merge without approval using the agent's credentials; both should fail
CI as a gateBroken or insecure code merges because the agent claimed it was fineRequired status checks; workflow files under code owners; manual approval for agent-triggered workflowsOpen an agent PR with a deliberately failing test; merge should be blocked
SandboxingDamage to the host, other projects, internal networks or production dataContainer or VM per task, egress allowlist, no production database credentialsFrom inside the sandbox, try to reach a domain not on the allowlist and the production database; both should fail
Audit log, kill switch and rollbackNobody can tell what happened, stop it or undo itTamper-resistant action logs, documented credential revocation, revertible deploysRun 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

An autonomy ladder for AI coding agents, with the safeguards each level needs
LevelWhat the agent can doWho approvesSafeguards required before this level
0. Suggest onlyRead code and propose changes or plans; a person applies themThe person applying the changeSeparate identity, read-only access, no secrets in context
1. Edit locally, ask before actingEdit files and run commands in a sandbox, asking before risky stepsThe developer, step by stepSandbox or container, egress allowlist, deny rules for secret files
2. Pull request with reviewPush to its own branch and open a PR; cannot approve or mergeA human reviewer who did not start the taskAll seven safeguards: protected main, required checks, audit log, kill switch
3. Auto-merge low-risk changesMerge narrowly defined changes automatically when every check passesA policy agreed in advance, with spot checksStrong test coverage on affected paths, path-based rules, fast rollback, monitoring and alerts
Never autonomousSee the list belowAlways a named personNot 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

  1. Deploying to production or promoting a release.
  2. Running database migrations against production, or deleting or bulk-updating production data.
  3. Changing authentication, authorisation, roles or permission logic.
  4. Creating, reading, rotating or deleting secrets and credentials.
  5. Editing CI/CD workflows, branch protection, repository settings or its own permissions.
  6. Anything that moves money: payment configuration, refunds, pricing or billing changes.
  7. Changing infrastructure, DNS, networking or access policies.
  8. Sending messages to customers or third parties, or publishing public content.
  9. Installing new MCP servers, plugins or dependencies from sources nobody has reviewed.
  10. 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.

Frequently asked questions

What is excessive agency in AI agents?

Excessive agency is a risk in the OWASP Top 10 for LLM Applications. It describes an AI system with access to tools taking damaging actions because its output was unexpected, ambiguous or manipulated, for example by prompt injection. OWASP attributes it to excessive functionality, excessive permissions and excessive autonomy.

Should an AI coding agent use my GitHub account?

No. Give each agent its own identity, ideally a GitHub App or a dedicated account with fine-grained, repository-scoped and expiring credentials. If an agent uses your account, its actions are indistinguishable from yours in logs and a leaked credential exposes everything you can access.

Can an AI agent merge its own pull requests?

It should not. Protect the main branch so merges need approval from a human who did not start the task, and make CI checks required. GitHub states that its Copilot cloud agent cannot approve or merge its own pull requests, and the person who asked for the pull request cannot approve it.

Is a prompt instruction enough to stop an agent doing something dangerous?

No. Instructions in a prompt or context file guide behaviour but can be misread or overridden by injected content. Dangerous actions should be blocked by controls outside the model, such as missing credentials, branch protection, required checks, permission deny rules and network allowlists.

What is the quickest way to stop a misbehaving AI agent?

Revoke or suspend its credentials, for example by suspending or uninstalling its GitHub App, stop the runner or container it uses and disable any scheduled triggers. Then revert its changes. Write these steps down and rehearse them before you need them.

Sources

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.

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.