The most important instruction an AI coding agent receives may be the one nobody writes. It is the repository itself: the nearby authentication helper, the C++ allocation pattern, the middleware that has always handled a request this way. A developer may ask an agent to add an ordinary feature and explicitly request secure code. Yet the existing project can supply a more concrete example than the instruction. A new study suggests that this is not merely an occasional coding mistake; it is a mechanism by which insecure software habits can replicate as agents contribute more code. The practical implication is uncomfortable. Organizations cannot evaluate an AI coding deployment only by asking whether the model knows secure patterns. They must ask which patterns their own codebase teaches it.

A controlled comparison, not a claim about every coding assistant

In a November 8, 2026 preprint, researchers Chenhao Sun, Niels Mündler-Sasahara, Mark Vero and Martin Vechev tested coding agents under matched tasks with different surrounding code. One experiment covered 96 backend application tasks in repositories containing neighboring applications. Another used paired repository-level C/C++ tasks involving memory safety. They report that insecure neighboring examples reduced the share of implementations that were both correct and secure by 3.4% on average in the backend setting. In the C/C++ setting, the average gap between secure and insecure contexts reached 35.4%. Those figures describe distinct experimental settings, not a universal error rate, and a measured difference should not be mistaken for the proportion of every commercial application that is vulnerable.

The striking element is the direction of the effect. The task could remain the same while the neighboring example changed, shifting the agent's output. Asking the agent to be security-conscious helped but did not eliminate propagation. Asking it to follow existing style made the tendency stronger. The researchers also observed that agents cited other code sites as reasons for implementation choices in 76.5% of examined explanations, while recognizing the introduced vulnerability in 69.9% of cases. Self-reported explanations cannot conclusively reveal internal model reasoning, but they reinforce the observable contrast: access to an example can steer behavior even when a system can describe the example's defect.

The repository becomes a behavioral dependency

Software engineering has always had the problem of copy-and-paste bugs. AI agents create a different scale and feedback loop. A human teammate may inspect one nearby function, question its assumptions and ask why it exists. An automated agent optimizing for completion can search dozens of files, synthesize what appears locally conventional and reproduce it consistently. Each generated module may then become fresh context for the next task. In that sense an old insecure idiom becomes more than historical technical debt; it becomes training-like material inside an ongoing development process. The agent's model weights need not change for the repository to influence it. The examples are supplied again with every task.

That observation also changes what a security review should prioritize. Reviewing only the final pull request catches some defects after they appear, but it does not reduce the probability that tomorrow's agent will copy the same insecure pattern from the untouched source. An organization facing a large legacy system may get more lasting protection from repairing one shared authentication helper than from issuing another natural-language policy instructing agents not to misuse it. This is a hypothesis about engineering leverage, not a number established by the study. The causal mechanism suggested by the controlled experiments makes it worth testing in real projects.

Why a stronger model alone is not a complete answer

It is tempting to interpret these results as a temporary shortcoming of particular coding models. As coding models improve, perhaps they will identify and reject vulnerable examples automatically. That possibility deserves attention: the preprint's tasks, models and evaluation methods cannot establish performance for every future agent, language or deployment. Nor does it prove an agent is inherently less secure than a human developer working from the same repository. Humans also imitate established local practice. The more defensible conclusion is narrower: model capability and environment quality are separate security variables. Improving one should not be assumed to neutralize the other.

There is a second counterargument. A team may claim that conventional testing, static analysis and code review already address these risks. Sometimes they do. But a passing functional test is evidence that code performs an intended behavior, not necessarily that it respects least privilege, rejects malformed input or handles memory ownership safely. A static scanner's usefulness depends on coverage and configuration. Security tests that assert only known misuse cases can miss a copied anti-pattern in a newly exposed path. The goal is not to replace those controls with an AI-specific product. It is to move checks earlier, closer to the examples the agent will consume, and to measure security outcomes alongside feature completion.

A practical intervention: clean the exemplars

Consider a company that uses an agent to add tenant-aware API endpoints. The existing repository contains several endpoints that derive tenant scope from a client-supplied parameter rather than the authenticated identity. An agent asked for a new endpoint may infer that this is the standard approach, especially if examples are consistent. A mitigation is to first create a secure reference implementation and a test that attempts cross-tenant access. Tell the agent where the vetted pattern lives; restrict its ability to treat unreviewed examples as authoritative. Require a security-oriented diff review for authorization logic. This example is illustrative, not a documented incident in the research.

For C and C++, the equivalent reference set should include memory allocation and lifetime examples with checked bounds and explicit ownership. Teams could mark vulnerable idioms in code-search results and prioritize replacing them before agent-driven refactoring. A repository-level policy document can help communicate expectations, but it should be backed by runnable checks. NIST's Secure Software Development Framework has long advocated addressing root causes rather than merely patching individual symptoms. The new agent evidence supplies another reason to take that idea literally: reducing the stock of unsafe examples may also reduce the flow of future unsafe additions.

What to measure before scaling agents

A sensible pilot can test the hypothesis without relying on slogans. Select representative tasks, run an agent against a baseline repository and a separately hardened copy, and evaluate both versions with the same functional and security test suite. Track security-sensitive code paths changed, classes of vulnerability introduced, how often known-bad examples were consulted, and reviewer time per accepted change. Separate failed attempts from shipped vulnerabilities; both matter, but they are different. Record which tooling, prompts and repository snapshots were used so that comparisons are reproducible. Avoid drawing conclusions from a handful of cherry-picked examples.

Procurement questions should change as well. A buyer comparing coding assistants might ask how each system treats repository context, whether tool access and index scope can be limited, and whether source-code retrieval records are available for audit. A vendor demonstration that repairs a synthetic flaw is not the same as evidence that its agent resists insecure patterns in an organization's own repositories. Vendors can reasonably protect proprietary implementation details, but they can still support controlled evaluation against realistic code and transparent acceptance criteria. The burden of proof belongs at the intersection of model, repository and workflow, rather than with a single leaderboard score.

The security debt multiplier is conditional

The study does not show that every agent-generated commit adds vulnerabilities. It does not quantify a global increase in exploited incidents or forecast a specific rate of software deterioration. It does show that a local environment can change the security quality of outputs under controlled conditions. The longer-term risk follows conditionally: if insecure examples persist, agents repeatedly consult them, and teams accept changes with limited security scrutiny, then inherited patterns can compound. Reverse those assumptions and the same automation may help remove accumulated debt faster than manual efforts can. That is the opportunity behind the warning.

Bottom line

The next generation of secure AI coding will be judged less by whether an assistant can recite security rules and more by whether its working environment consistently makes secure choices the easiest ones to imitate. Repairing old code, curating known-good examples, testing dangerous behaviors and enforcing review at sensitive boundaries are not glamorous features. They are the foundation that decides whether faster software generation creates faster remediation or faster replication of mistakes. The repository is already part of the prompt. Security teams should treat it that way.

Agent behavior also depends on the permissions around its tools. See our analysis of proof of permission for AI agents and why formal proofs still need a chain to running code.

Sources and methodology

Research findings are attributed to the authors' November 2026 preprint. Organizational recommendations, forecasts and examples are Nextwith.ai analysis, not conclusions independently demonstrated in the experiments. The paper is a preprint; results require independent replication in production environments.