Prevent this by separating code authoring from merge authority, so the agent can open a pull request but cannot approve or merge it. Enforce a live policy check on the merge path, require human review or signed approval for protected branches, and keep the agent’s token limited to write access on a fork or branch, not repository admin rights.
Why an AI Agent Should Be Able to Propose, Not Merge
The core control is separation of duties. An agent can still draft code, open a pull request, and even suggest reviewers, but it should not hold the authority to approve or merge its own work. That boundary matters because merge rights turn a helper into an autonomous release actor, which raises the blast radius of any bad output, prompt injection, or over-scoped token.
Keep the merge path under a live control, not a polite convention. If the branch is protected, the merge should fail unless the required reviewer state, policy checks, and approval conditions are satisfied by someone or something outside the agent’s execution chain.
For teams building agentic workflows, the practical model is simple: authoring may be delegated, final change acceptance may not. That distinction is especially important when the agent can reach source control, CI, or deployment tooling, because those adjacent capabilities can make a small code change operationally significant.
How to Structure the Control Boundary
The safest pattern is to limit the agent to a constrained write path, such as a fork, feature branch, or scoped workspace, while keeping protected branches and release gates outside its authority. That way the agent can prepare changes, but the system still requires an independent human or policy-enforced approval step before the change can land.
Use branch protection as a hard stop, not an after-the-fact review aid. Require explicit status checks, mandatory review, and approval signatures or equivalent trusted attestations on the merge path. If your platform supports policy-as-code or a merge-time decision check, put the final decision there so the agent cannot bypass it through a direct API call or an alternate automation route.
Identity and token scope should match that design. The agent’s credentials should allow the minimum needed to create or update a pull request, but not repo administration, branch override, or self-approval powers. The moment the same principal can both author and accept a change, the control boundary becomes mostly procedural rather than technical.
What Good Looks Like in Practice
A well-designed setup makes the agent useful without making it trusted. The agent can generate diffs, request review, and respond to feedback, but the approval and merge event remain observable, attributable, and externally controlled. That separation should hold even if the agent is running in a CI job, acting through an integration token, or chained into a broader developer workflow.
This is where teams often underestimate risk. A coding agent does not need broad privileges to be dangerous if it can create a seemingly valid pull request that later merges automatically, or if it can manipulate the checks that gate its own merge. The control should therefore be tested from the agent’s perspective: can it create the change, can it influence the checks, and can it complete the merge without a person outside the workflow?
When the answer to any of those questions is yes, the boundary is too soft. The right fix is usually not more linting or more prompt guidance, but a stronger separation between change creation, review, and final authority.
Risk and Threat Considerations
Self-merging agents create a governance weakness and a trust problem at the same time. If the same autonomous actor can author code, satisfy or spoof the required checks, and merge the result, then a single compromised instruction, malformed prompt, or excessive token scope can move directly from code generation to production impact.
Failure mechanism: The agent is granted both creation capability and acceptance capability, so the normal human checkpoint disappears. A bad change can then be merged through automation, or a malicious instruction can cause the agent to approve its own unsafe output.
Impact: The organisation loses meaningful separation of duties, increases the chance of unreviewed or unsafe code reaching protected branches, and makes later attribution and rollback harder if the agent’s action chain is not fully logged.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10 addresses the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | ASI03 — Identity & Privilege Abuse | Self-merging agents are an identity and privilege misuse problem. |
| ASI02 — Tool Misuse | The agent must not use repo tools to complete its own merge path. | |
| Recommendation — Enforce separate approval and merge authority for agent-controlled changes. Restrict tool permissions so the agent cannot invoke merge actions on its own work. | ||
| NIST SP 800-53 Rev 5 | AC-6 — Least Privilege | The answer depends on limiting the agent’s repository permissions. |
| AC-3 — Access Enforcement | Protected branches need enforced policy checks on merge actions. | |
| CM-5 — Access Restrictions for Change | Branch protection and change control limit who can make authoritative changes. | |
| Recommendation — Grant only the minimum source-control permissions needed to open pull requests. Enforce merge-path controls that deny self-approval and unauthorized merges. Require approved change control before any protected-branch merge. | ||
Practitioner Guidance
What to verify: Test the full merge path from the agent’s identity, not from a human account. Confirm that the agent can open a pull request but cannot approve it, cannot satisfy branch protection by itself, and cannot gain a merge path through an alternate API, service token, or privileged automation hook.
Decision rule: If the agent can touch source code but can also finalise the change, treat that as a privilege design flaw, not a workflow preference. Reduce scope first, then reintroduce automation only where the merge decision remains independently controlled.
Practitioner takeaway: The safest agentic development model is “create, propose, and wait,” not “create and commit.” Keep merge authority outside the agent’s reach so the last security decision remains separate from the code-generation step.
Related resources from NHI Mgmt Group
- Guide: Red Teaming AI Agents for Identity Abuse
- What is the difference between human identity governance and AI agent governance?
- When does AI agent access create more risk than it reduces?
- What is the difference between governing human access and governing AI agent access?
- When do AI agent credentials create more risk than they reduce?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 16, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org