The Evolution of Agentic Coding and Its Security Governance
This article explains why AI coding is shifting from code completion to agentic coding, where models autonomously decompose tasks, make decisions, and execute commands. It breaks down the three-stage workflow, key architectural differences such as project-level scope and multi-agent collaboration, and the typical supply chain risk of "ghost dependencies," including threat models T1 and T2. It also covers cost management under high resource consumption and practical guardrails for enterprise adoption, including sandboxed execution, reviewable changes, least privilege, full-chain auditing, and human-in-the-loop checkpoints.
1. From Completion to Autonomy: Why the Shift Is Inevitable
The core interaction of traditional AI coding tools is “humans write code, the model completes it.” The model’s scope is limited to the current file and the area around the cursor, and decision-making authority always stays with the human. As large models have improved in reasoning and tool calling, a new mode known as agentic coding has gradually taken shape: the model is no longer just a text generator, but an execution entity that can autonomously break down tasks, compare technical options, read and write the file system, and run build and test commands.
There are three fundamental drivers behind this shift. First, the real granularity of software tasks is “from requirements to a runnable system,” not “the next line of code,” so file-level completion cannot close the loop by nature. Second, verification costs have dropped: compilation, unit tests, and static checks can all be invoked automatically, giving the agent a feedback loop for self-correction. Third, larger context windows and stronger retrieval make global reasoning across files and modules possible.
It is important to emphasize that the transfer of control is not a simple stacking of capabilities, but a restructuring of the risk profile. When the execution entity changes from a human to an agent, the attack surface expands from “code written incorrectly” to “decisions being poisoned, commands being executed, and dependencies being introduced.”
2. The Three-Stage Workflow: How Agents Make Decisions
A typical agentic coding task can be abstracted into three stages, and understanding this chain is the prerequisite for good governance.
- Intent understanding: User input is often vague, elliptical, and carries implicit constraints in natural language. The agent needs to fill in missing information and form verifiable task assumptions, such as the target artifact, compatibility boundaries, and performance and security constraints.
- Decision generation: The agent autonomously decides which third-party components to introduce, which version to choose, and what directory structure and interface abstractions to adopt. This stage is the main injection point for supply chain risk.
- Execution: The agent generates dependency manifest files, modifies project configuration, runs install and build commands, and iteratively fixes issues based on errors.
A schematic execution chain can be expressed as:
User intent -> Task decomposition -> Solution and dependency decisions -> File system writes-> Command execution (install/build/test) -> Result verification -> Rollback or convergence
The key point is that errors in the second stage do not stay at the “suggestion” level; they are actually executed in the third stage. This is the essential difference between agentic coding and conversational Q&A.
3. Core Technical Differences: Project-Level Scope and Multi-Agent Collaboration
Compared with traditional tools, agentic coding has two decisive architectural differences.
The first is that the read/write scope rises from the file level to the project level. An agent can search across directories, perform batch refactoring, and unify style and interfaces. This brings significant efficiency gains, but it also means a single misjudgment can pollute the entire repository. Therefore, engineering practice must introduce “scope declaration”: an explicit allowlist of paths that may be read or written, sensitive directories that must not be touched, and change-size thresholds that trigger human confirmation when exceeded.
The second is the coordinated invocation of multiple tools and multiple agents. Complex tasks are split among different roles responsible for retrieval, coding, testing, and review, which collaborate through messages and shared context. Collaboration improves throughput but also amplifies the risk of prompt injection and error propagation: a poisoned upstream conclusion is treated as established fact by downstream roles and amplified further. A workable approach is to have each role output structured conclusions with evidence references, have downstream roles accept only traceable inputs, and keep an independent review role for key decisions.
4. Ghost Dependencies: A Typical Supply Chain Risk in Agentic Coding
“Ghost dependencies” refer to dependencies introduced by an agent that do not actually exist or are not verified versions. They mainly take two forms.
- Version ghosts: The model tends to reproduce old versions that appear frequently in the training corpus, binding the project to historical versions with known vulnerabilities.
- Name ghosts: The model may “fabricate” component names that do not exist, forming purely hallucinated references.
This yields two threat models:
- T1: Exploitation of known vulnerabilities in outdated component versions. The attacker needs no active behavior; as long as the project continues to use an old version with a public vulnerability, it may be automatically scanned and exploited.
- T2: Targeted poisoning of hallucinated component names. An attacker pre-registers package names in public repositories that “look very reasonable and are extremely likely to be generated by the model,” plants malicious code in them, and waits for the agent to install them. The stealth of this attack lies in the fact that it does not need to deceive a human, only the model’s generation distribution.
Governance should cover two layers at once: “do not introduce” and “block it even if introduced.”
# Dependency admission policy examplepolicy:allow_versions: "Only locked versions allowed; floating ranges prohibited"deny_suspicious_names: "Newly appearing package names require human confirmation"require_lockfile: trueblock_install_scripts: true # Prohibit automatic execution of install-time scriptsvulnerability_gate: "Block merge if high-severity known vulnerabilities exist"
In engineering practice, teams should insist on dependency locking and integrity verification, prefer trusted internal mirrors and private repositories, and enforce “review before install” for new dependencies, while setting vulnerability gates and license checks in continuous integration. Dependency manifests generated by agents must be treated as untrusted input and go through the same review process as human submissions.
5. Operational Characteristics: Cost Management Under High Resource Consumption
Agentic coding is characterized mainly by high resource consumption. A single task involving cross-file changes and multiple rounds of verification can consume orders of magnitude more tokens and compute than a single Q&A turn. Without constraints, cost rises nonlinearly with task complexity.
Actionable cost-control measures include: tiered model scheduling, assigning light tasks such as retrieval and formatting to small models and architecture decisions to stronger models; context budgeting, setting context and turn limits per task and requiring human intervention when exceeded; caching and reuse, building caches for retrieval results, build artifacts, and test reports; and observability, measuring task duration, call counts, and failure rates through logging services and monitoring alerts, forming a cost baseline and setting anomaly alerts.
6. Implementation Recommendations: Putting Agents Inside Controllable Engineering Guardrails
For enterprises introducing agentic coding capabilities, we recommend building guardrails in the following order.
- Sandboxed execution environment: Run with least privilege on a container platform, restrict network egress, mount sensitive directories read-only, and prohibit install-time scripts.
- Reviewable changes: Submit all output as patches, mandatorily passing code review and automated tests, and prohibit direct pushes to the main branch.
- Least privilege: Make credentials short-lived and grant them per task, and prohibit the agent from reading secret configuration unrelated to the task.
- Full-chain auditing: Record decision rationale, executed commands, and change diffs so that issues are traceable and incidents are attributable.
- Human-in-the-loop nodes: Retain human confirmation for three high-risk decision types: dependency introduction, architecture selection, and data access.
Overall, the value of agentic coding comes from “autonomous closure,” and so does the risk. Only by solidly handling four things—scope, dependency admission, execution sandbox, and cost budget—can a sustainable balance between efficiency and security be achieved. For teams that want to build such capabilities quickly, an engineering foundation can be built on general-purpose cloud capabilities such as container platforms, image repositories, logging services, and monitoring alerts, without binding to any specific vendor’s proprietary interfaces.
