Independent analysis by NHI Mgmt GroupSource article: Clover Security, “Looks secure, ships insecure: Why broad security context backfires across frontier coding agents” (July 29, 2026)

TL;DR: Coding agents prevented only about 17% of planted flaws with no security context and 33% with broad guidance, but feature-tailored context reached 84%, according to Clover Security's research across three production codebases and three frontier models. Broad context can produce security-shaped code that still ships business-logic flaws, so the decisive control is precise feature-level instruction, not more threat-model volume.


At a glance

What this is: NHI Mgmt Group's analysis, drawing on Clover Security's research: Coding agents become materially safer only when security context is tailored to the feature, not when teams add more generic guidance.

Why it matters: This matters because security and platform teams are increasingly delegating code generation to agents, and generic threat models can create false confidence while leaving business-logic flaws intact.

By the numbers:

  • Coding agents prevented only about 17% of planted flaws with no security context.
  • Broad security context improved the average to 33%.
  • Feature-tailored context reached an average mitigation rate of 84%.
  • One planted requirement allowed only 10% of collaborator read events to be logged.

Context

Coding agents now sit inside the software delivery path, which means their security posture depends on the quality of the context they receive. Generic guidance can describe risks in the abstract, but it does not reliably tell a system how to resolve a feature-specific weakness when product logic itself creates the exposure.

The governance problem is not only prompt quality. It is the gap between an organisation's security knowledge and the exact implementation decision an agent must make in a live codebase. That gap is especially visible when a feature requirement conflicts with the control that should constrain it, because the agent can produce code that looks secure without actually enforcing the right outcome.

As more teams delegate feature work to coding agents, the operational question becomes whether security context is actionable enough to change the generated implementation, not merely informative enough to influence the plan.


Key questions

Q: How should teams prompt coding agents for secure code?

A: Prompt coding agents with narrowly scoped security requirements tied to the feature, such as input validation, authentication checks, least privilege, and safe error handling. State the acceptable libraries, data boundaries, and test expectations so the agent optimises for feature-specific security outcomes instead of producing generic code. Review the result for unsafe assumptions, insecure defaults, and hidden permission changes.

Q: Why do broad threat models fail to secure generated code?

A: Broad threat models fail because they describe general risks without translating them into concrete code constraints, attack paths, or testable controls. A coding agent can still generate insecure logic, weak validation, excessive permissions, or unsafe dependency use if the prompt does not specify the feature, trust boundaries, and required defences. Security has to be expressed as implementable instructions, not only risk categories.

Q: How do teams know whether AI-generated patches are actually safe?

A: They need independent validation that checks for exploitability, regression, and build integrity before a patch reaches merge or deployment. A fix is not safe just because the agent produced it. Teams should look for evidence that the patch preserves behaviour, passes tests, and has a clear review trail.

Q: What is the difference between a threat model and a build instruction?

A: A threat model identifies assets, trust boundaries, likely attackers, and abuse paths. A build instruction tells the coding agent what to implement and how to implement it, including security checks, input handling, authentication, and logging. The first informs risk analysis, while the second shapes the generated code and its control flow.


Technical breakdown

Why broad security context compresses away the control that matters

Coding agents do not consume every instruction at full fidelity. They compress large context sets into shorter working summaries, which means security vocabulary often survives while the precise control instruction is weakened or lost. In practice, a broad threat model can tell the agent that a feature touches privacy, logging, or authentication without specifying the exact rule the finished code must enforce. That is enough to make the output sound security-aware, but not enough to guarantee the right behaviour in the implementation.

Practical implication: Treat repository-level security guidance as background, not as proof that the feature is correctly secured.

Why security-looking code can still ship a flaw

The harder failure mode is false assurance. An agent can cite risk, add audit calls, and even satisfy tests while the underlying business logic still permits the unsafe outcome. That happens when the context gives the agent the language of security but not the decision boundary it must encode. The result is code that appears reviewed because it contains familiar control words, yet the actual control objective remains unmet. Read Top 10 AppSec Programme Mistakes.

Practical implication: Require implementation evidence of the control outcome, not just security terms in the plan or test suite.

Feature-tailored context changes the threat model from reference material to build instruction

Feature-tailored context works because it identifies the exact threat created by the feature, the attack path that follows from it, and the countermeasure the finished code must exhibit. That shifts the agent from reading about risk to executing a design constraint. For secure code generation, the useful unit is not a general policy statement but a concrete behavioural requirement tied to the feature's own failure mode. See the Secure Software Development Lifecycle (SSDLC) Guide.

Practical implication: Write context as enforceable outcomes, such as what the code must return, deny, expire, or log under specific conditions.


Threat narrative

Attacker objective: The objective is to get unsafe application logic into production while surrounding evidence makes the change appear secure.

  1. Entry occurs when a coding agent receives broad, feature-agnostic security context instead of a precise control instruction for the feature it is building.
  2. Escalation follows when the agent translates that context into security language and tests, but not into a control that blocks the underlying unsafe behaviour.
  3. Impact is insecure software that looks reviewed and compliant while still shipping the business-logic flaw the agent was supposed to prevent.

Read and download The State of NHI & AI Agent Breach Report 2026, covering 200+ breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Generic security context is not a governance control. Broad threat models, checklists, and security skills can improve awareness, but they do not reliably bind an agent to the exact implementation outcome a feature requires. In identity and access terms, the same mistake appears whenever organisations assume that describing a risk is equivalent to constraining the behaviour that creates it. The control problem is specificity, not volume, and the governing question is whether the instruction changes the emitted code.

False assurance is the more dangerous failure mode than missed detection. When an agent produces code that cites risk, adds tests, and still leaves the defect intact, reviewers can be misled into accepting work that merely sounds secure. That is a process failure as much as a code failure, because it weakens the human review function that should catch the gap. The right response is to demand evidence of the intended control outcome, not evidence that security words appeared in the workflow.

Feature-tailored context is a named capability gap: outcome-specific security instruction. It closes the distance between the feature's risk and the behaviour the implementation must enforce. That matters across software delivery, IAM-adjacent controls, and agentic AI workflows because the same pattern recurs whenever a system can describe a policy without implementing it. Teams should treat this as a design requirement for agent governance, not a prompt-tuning problem.

Business-logic flaws expose the limit of generic secure-code guidance. A flaw can be logically unsafe even when it matches the specification and passes tests, which means security has to intervene before the agent finalises the behaviour. The lesson for practitioners is to move security requirements into the feature definition itself, where the implementation decision is made.

Security context must act like a control, not a reading list. The stronger the delegation to coding agents becomes, the more important it is to express required outcomes in executable terms the agent cannot reinterpret. That is the difference between advising on risk and governing the generated code.

From our research library:

What this signals

Outcome-specific security instruction: the practical unit of governance for coding agents is no longer the general policy or threat model, but the exact control outcome the generated code must satisfy. As organisations adopt agentic development more broadly, security teams will need to move context closer to the feature decision point and away from repository-level generalities. That shift will matter more than adding another checklist because the agent can only enforce what it can operationalise.

The same pattern will show up wherever implementation systems can summarise risk without encoding the control. Broad guidance can raise awareness, but it also increases the chance that teams mistake security language for security enforcement, which is why review processes have to test the emitted behaviour rather than the surrounding rationale.

Security teams are already worried that AI systems may learn and reproduce sensitive information patterns from codebases, according to the State of Secrets in AppSec. That concern becomes more urgent when agentic tools are allowed to reason over repositories without a control boundary that names the exact outcome they must preserve.


For practitioners

  • Define feature-specific security outcomes before prompting the agent State the exact behaviour the finished code must enforce, such as which fields can be returned, which events must be logged, and which actions must be denied under specific conditions.
  • Separate reference context from binding instructions Use repository threat models, checklists, and skills as background material, then add a short control statement that the agent must implement even if the feature spec conflicts with it.
  • Review for false assurance signals in generated code Check whether the plan, code comments, and tests use security language without proving that the unsafe behaviour was removed or constrained in the implementation.
  • Measure agent outputs by resolved flaws, not by apparent security effort Track whether the delivered change actually eliminates the planted business-logic weakness instead of counting references to threats, policies, or tests that appear security-aware.

Key takeaways

  • Generic security context can make coding agents sound safer without making their output safer.
  • Feature-tailored instructions materially outperform broad guidance because they bind the exact control outcome to the feature.
  • Governance for coding agents should judge the implementation effect, not the presence of security language in plans or tests.

Related NHI Mgmt Group resources: AI Coding Agents Security Guide · Threat Modelling AI Agents · Security Requirements and Abuse Cases Guide · Top 10 AppSec Programme Mistakes


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 AI RMF, NIST CSF 2.0 and OWASP SAMM set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Agentic AI Top 10ASI03 — Identity & Privilege AbuseCoding agents can be misdirected by weak context into unsafe implementation behaviour that looks controlled.
ASI02 — Tool MisuseThe article shows how an agent can use security context without applying the right control action.
Recommendation — Bind agent outputs to explicit privilege and behaviour constraints before code is accepted. Constrain tool and output use so the agent cannot treat reference material as a substitute for implementation control.
NIST AI RMFGOVERN — AI Governance and AccountabilityThe issue is governance of how AI systems are instructed, reviewed, and held accountable.
Recommendation — Establish governance for prompt-to-code controls and review outputs against required behaviour.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsThe examples include agent-driven access and logging decisions that depend on correctly scoped authorisation behaviour.
Recommendation — Verify that generated code enforces the intended permissions and entitlement boundaries.
OWASP SAMMSecurity Requirements — Security RequirementsThe article is about turning security requirements into implementation-ready instructions.
Recommendation — Define security requirements as testable outcomes before code generation begins.

Key terms

  • Security context: Security context is the meaning attached to telemetry, such as identity, privilege, chronology, and attack relevance. Data without context may still be stored, but it is far less useful for detection or investigation because teams cannot tell why the event matters or how it fits an incident.
  • Coding Agent: A coding agent is a software system that can plan, generate, and modify code with limited human prompting. In governance terms, it is not just a tool but an actor whose permissions, tool access, and rollback path must be managed as part of the delivery process.
  • Business Logic Flaw: A business logic flaw is a weakness in how an application handles intended behaviour, such as permissions, workflow order, or transaction state. These flaws often bypass signature-based checks because the problem is not a malformed input, but a legitimate action used in the wrong sequence or context.
  • Threat Modeling: Threat modelling is a structured view of what you are defending, who might attack it and how. It maps assets, trust boundaries, access points and likely abuse cases, often for an application before or during development, so teams can design matching controls. Threat intelligence keeps models grounded in real actor behaviour rather than imagined attacks.

Deepen your knowledge

NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, agentic AI identity, machine identity security, IAM, human identity, identity lifecycle, and secrets management. It helps security, identity, and platform teams apply governance patterns to the systems their programmes now depend on.
NHIMG Editorial Note
Published by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org