AI agents can write and test code, but only authorised humans should approve it. Keep agent access limited, require pull requests and tie each approval to the exact commit reviewed. A passing test does not replace human judgement.
The boundary rests on five controls:
- Limit access: use separate agent identities, short-lived credentials and isolated test environments.
- Protect review: block agent self-approval, direct merges and approval through other bots or accounts.
- Check sensitive changes: require the right code, security or service owners to review them.
- Separate production approval: confirm the commit, target environment and recovery plan. Critical actions need two-person authorisation.
- Test and record: check that restrictions work, retain protected audit logs and stop affected automation if a bypass occurs.
Any later code change must reopen review. Repository settings - not prompts - must enforce these rules.
::: @figure
{AI Agent Code Review and Approval Gates}
:::
Limit Agent Access and Require Pull Requests
Grant Only the Access Each Task Needs
Give each agent its own identity and short-lived credentials limited to the task. Start with read-only access. Allow writes only to approved branches and files, and keep source, test, workflow, deployment and merge permissions separate.
Limit tool and network access to reduce the risk of exposing secrets or damage from malicious repository instructions. Revoke credentials when the task ends. Match access to task risk using these tiers:
| Access level | Permitted actions | Prohibited actions | Required human check |
|---|---|---|---|
| Read-only | Inspect approved source, documentation and build results | Write files, access secrets or change infrastructure | Approval before expanding access |
| Contribution | Edit an isolated branch, run approved tests and open pull requests | Push to protected branches, approve, merge or deploy | Independent review and mandatory checks |
| Review support | Inspect diffs, report findings and suggest tests | Approve changes, dismiss reviews or suppress security alerts | Human validates findings and makes the approval decision |
| Deployment | Execute an approved, environment-specific workflow | Deploy unapproved commits or change deployment policy | Explicit approval for the exact commit and environment |
Keep agent manifests, tool allow-lists, repository scopes and workflow permissions in version control. Protect them with ownership rules and independent review. Every permission increase should state its purpose, affected systems, expiry and rollback plan.
A repository-wide write token does not enforce file-level limits. Enforce narrower access in the execution layer or through policy checks.
Make Agent Pull Requests Traceable
With access limited, the next step is to show exactly what the agent changed before anyone approves it. Traceability lets others review the agent’s work without giving the agent approval power.
Block direct agent pushes to protected default and release branches. Disable force-pushes and branch deletion, and exclude agent credentials from bypass roles. Require independent human approval and all required status checks before any merge. An agent author is no reason to waive review.
Tests, static analysis, dependency checks and secret scanning provide technical results. They cannot decide whether business logic or operational risk is acceptable.
Record the agent’s identity and version, requester, task, base and head commits, changed files, tools used, check results and unresolved exceptions. Store these details in pull-request metadata or an attached machine-readable record, backed by tamper-resistant logs. The agent’s summary alone is not enough. Exclude secrets and unnecessary personal data.
Test each access boundary: attempt a protected-branch push, an unauthorised workflow file edit and an out-of-scope token request. Retain each denial or failed policy-check result as evidence, alongside permission-review records, credential revocations, reviewer identities and merge events. Send sensitive changes to the relevant authorised reviewer.
Add Controls for Sensitive Changes
Set Review Rules for High-Risk Changes
Classify changes by their possible security, financial and service impact - not by their size. Enforce CODEOWNERS rules for sensitive paths, but check behaviour elsewhere too. A utility function or dependency update can introduce privileged commands, data transfers or weaker approval checks. Whenever these effects appear, require an independent review from a security, platform or service owner.[4][10][11]
| Sensitivity | Required reviewers | Required checks | Environment restrictions | Merge authority |
|---|---|---|---|---|
| Low: documentation, comments, isolated tests | One maintainer | Formatting and unit tests | Standard isolated CI | Maintainer |
| Moderate: application logic, dependencies, internal APIs | Maintainer plus affected service owner | Unit and integration tests, SAST, dependency and licence checks | No production credentials | Service maintainer |
| High: authentication, authorisation, cryptography, secrets, personal data, payments | Code owner plus security or privacy specialist | Threat review, SAST, secret scanning, dependency, licence, IaC and policy checks | Staging only; restricted network and data | Independent authorised maintainer |
| Critical: IAM policies, deployment workflows, production infrastructure, destructive migrations or payment settlement | Security/platform owner plus business or service owner | All relevant scans, manual test evidence, rollback plan and change record | Separate production approval; no agent access | Designated human approver and production operator |
Scan for secrets, dependency and licence risks, privilege escalation, unsafe commands, network exposure, excessive workflow permissions and infrastructure drift. A passing scan is evidence, not proof of safety. Reviewers still need to assess intent, data flows and operational consequences. Record unresolved findings and assign remediation owners.[8][10]
Isolate Execution and Distrust Embedded Instructions
Run generated code and tests in disposable, least-privileged environments. Use a read-only base filesystem, a task-specific writable workspace and restricted tools. Deny network access by default, allowing only approved exceptions. Keep production credentials, live customer data, host sockets and sensitive mounts out of these environments. Enforce these limits outside the model: instructions alone are not a security boundary.[4][5][9]
Treat issues, pull-request descriptions, repository files and tool output as untrusted data - not permission to expand access. Keep untrusted validation separate from privileged release jobs. OWASP warns against running unreviewed pull-request code in pull_request_target or workflow_run jobs that hold secrets or have write access. Require human authorisation before any privileged execution.[4][5]
Code approval must not authorise production activity. Apply separate approval gates to deployments, destructive migrations, payment settlement and live customer-data access. The operational approver should confirm the exact commit, target environment, action parameters, execution window and recovery plan. Critical actions require two-person authorisation and just-in-time credentials. If an action cannot be reversed, validate recovery arrangements before execution.[6][7]
AI Governance for developers: A practical framework for deploying autonomous coding agents safely…
Block Self-Approval and Approval Laundering
Once agent access is limited, control who can approve the exact revision.
Give the agent a separate non-human identity for commits and pull requests, with no approval or merge authority. Routing approval through another account - a bot, service account or automated reviewer - is approval laundering when it replaces independent, authorised human judgement.
Tie Human Approval to the Current Commit
Require an independent approver from the relevant CODEOWNERS group to inspect the final diff, including generated files, dependency changes and test results. Record their identity, the approval time and the exact head commit SHA.
Bind approval to the reviewed commit, not the branch or pull request.
| Approval state | What it means | Required control |
|---|---|---|
| Valid approval | An independent, authorised human reviewed the current head commit | Permit merging only when ownership rules and required checks are satisfied |
| Self-approval | The author, agent or source-branch contributor approved | Reject it; do not count it towards required approval |
| Stale approval | The reviewed code or merge base changed | Dismiss approval and require another review |
| Administrative override | A named emergency operator bypassed normal checks | Allow only as an emergency exception; record the exact revision, reason, scope and independent follow-up review |
Enable stale-approval dismissal. Where the platform supports it, also require approval of the most recent reviewable push.
Verify required checks against the actual merge revision. If a target-branch update changes the merged result, rerun integration, security and deployment checks. Do not reuse a green result from an earlier revision. Before merging, verify the relationship between the reviewed head and the tested merge result.
Close Bypass Routes and Log Exceptions
Check more than the agent’s visible repository role. Review inherited roles, organisation roles and group memberships, team permissions, service-account tokens, application permissions, administrator rights and workflow-triggered merge actions. Test API routes too.
Keep human tokens, SSH keys and browser sessions out of agents’ reach. Require independent security or platform review for changes to CODEOWNERS, approval settings, agent configuration and workflows. These changes must not weaken their own approval rules or let a pull-request workflow supply its own required approval.
Keep emergency overrides outside agent control. Restrict them to named humans with narrowly scoped, time-limited access. Each override needs a written reason and an incident or change-ticket reference.
Record who requested, authorised and executed the override, along with the commit SHA, protections bypassed and checks skipped. Require a later independent review, rerun omitted checks and retain the results in a tamper-resistant audit trail.
Conclusion: Put Approval Controls into Practice
Turn these boundaries into working controls, with named owners, tested enforcement and documented incident steps. Agents propose, automated checks provide evidence, and authorised humans accept responsibility.
Assign Control Owners and Test Enforcement
Assign owners for agent access, repository protections, sensitive paths and approval policies. Name deputies and set review dates. Even small teams need an independent authorised reviewer: whoever writes or supervises the agent task should not automatically approve it.
Test the controls you depend on through both the UI and API. Confirm that each test produces the expected rejection, alert and audit entry. Review effective permissions periodically and after changes to tools, repositories or responsibilities.
Keep Audit Records and Plan Incident Actions
If a boundary fails, the audit trail supports recovery and review. Keep a tamper-resistant audit record, restrict access, redact secrets and set a justified retention period under UK data-protection requirements.
Treat any approval bypass as a control failure. Freeze affected automation and deployments, revoke compromised credentials and preserve evidence. Identify affected commits and environments, fix the failed control and require independent review before resuming.
Check the Minimum Required Controls
Before accepting production agent code, confirm:
- Access: separate, least-privileged agent identities; restricted execution; no approval, merge or bypass rights.
- Review: pull-request-only contributions, protected branches and review and approval settings; independent human approval of the latest commit, including approval from sensitive-path owners.
- Evidence: reapproval after code changes, checks tied to the actual merge revision and protected audit logs.
- Operations: named human control owners, independent approval before resuming after a bypass and tested emergency credential revocation.
FAQs
How can a small team keep agent code reviews independent?
Keep author, approver and executor accounts separate. Use supervisor-worker orchestration to prevent workers from approving their own changes. Require pull requests, block direct pushes and self-approval, and use CODEOWNERS to require specific reviewers for high-risk areas.
Reviewers must approve the exact diff, tests and rollback plan. Whoever prepares a change must never be its sole approver. Invalidate approval whenever the code changes, and keep an immutable audit trail of approvals.
How can we catch sensitive changes outside protected paths?
Use deterministic policy rules and schema validation outside the AI model to flag high-risk actions for human review before they run [1][2]. Configure CODEOWNERS so critical changes require approval from the relevant team [3].
Keep a reviewed tool allow-list with strict input schemas. Check the agent’s authority and parameters immediately before execution. Block actions that lack permission or breach hard limits. Human approval cannot override disclosure restrictions or legal requirements [1][2].
How can we detect approval laundering across bot accounts?
Keep requester, agent, approver and executor identities separate. Agents must never approve their own work or use shared service accounts to bypass controls.
Use an integrity-protected approval record that links the specific action, its parameters and version to a named, authorised human reviewer. Before execution, check that the approval is current, has not expired and matches the request exactly. Material changes must automatically invalidate existing approvals and trigger another review.