Ghost Dependencies in AI Agent Coding: Supply Chain Risks and Governance

    Autonomous coding agents can turn unreliable package names and outdated version choices into installed software dependencies. This article explains how these “ghost dependencies” arise, the supply chain threats they create, and why prompts alone cannot control them. It outlines practical governance measures, including approved dependency baselines, pre-installation validation, mandatory review gates, software bills of materials, and auditable workflows.

    AI agent coding is changing the boundaries of responsibility in software delivery. Developers previously controlled technology choices and dependency declarations, while code-completion tools offered suggestions for individual statements. Today, agents can interpret ambiguous goals, break down tasks, select third-party components, modify dependency manifests, and trigger installations.

    That increased efficiency also transfers control from people to a model-driven execution loop. It introduces an easily overlooked supply chain problem: ghost dependencies. Rather than a person deliberately introducing a known malicious package, an agent makes an unreliable dependency choice during planning and then automatically turns that choice into a runnable, potentially releasable software component.

    1. From Code Completion to Autonomous Execution: Why Risk Increases

    A typical agentic coding workflow has three stages.

    Interpreting intent. The agent translates a natural-language goal into an executable plan. Users often describe a business outcome, such as “complete the data validation and make the application deployable,” without specifying component names, version ranges, or license restrictions. These gaps leave substantial room for the model to make its own choices.

    Making decisions. The agent selects components and versions and determines module boundaries. Ghost dependencies are most likely to emerge here: choices may reflect frequent patterns in training data rather than the repository’s current lockfile, the organization’s approved baseline, or current security advisories.

    Executing decisions. The agent updates manifests, lockfiles, or build scripts, then invokes a package manager to download and install dependencies. Without a human approval gate, an incorrect decision can become a real file in the build environment within seconds—and subsequently enter container images, artifact repositories, and release pipelines.

    Compared with a workflow in which people write code and tools provide suggestions, four factors amplify the risk:

    1. Higher decision density. A single task may introduce multiple transitive dependencies.
    2. Broader execution permissions. Agents often have permission to modify the workspace and run installation commands.
    3. Delayed feedback. Developers see “task completed,” not the reasoning behind every dependency selection.
    4. Transferred trust. Teams may treat “it runs” as equivalent to “it is ready to ship,” bypassing component review.

    2. Two Forms of Ghost Dependencies

    A ghost dependency is a dependency that exists in a manifest or installation result, but whose name or version comes from a model’s statistical preferences or hallucinations rather than a controlled engineering decision.

    Version Ghosts

    A version ghost occurs when an agent selects an older version that appeared frequently in its training material. That version may still build successfully. Abundant examples and stable interfaces can even make it easier for the agent to pass tests on the first attempt.

    The problem is that older versions may have publicly disclosed vulnerabilities whose fixes are available in later releases. An agent optimizing only for compilation or the current test cases can systematically favor versions that are familiar but outdated.

    Transitive dependencies are harder to detect. A direct dependency may appear properly pinned while its transitive dependencies still resolve to outdated versions within permitted ranges.

    Name Ghosts

    A name ghost occurs when an agent proposes a package that does not exist, or a name that differs only slightly from a legitimate maintained project. The model may construct it by combining familiar naming patterns, such as functional terms, organization prefixes, and language-specific conventions.

    These hallucinations can be especially subtle around private namespaces, internal component aliases, or similarly spelled packages. If an external registry allows someone to register the invented name, what initially causes an installation failure becomes an available identifier that an attacker could claim.

    The two forms can overlap. A nonexistent name may later resolve to an attacker-published package, while its version number falls within a range familiar to the model. The resulting manifest may look complete and reproducible even though its components are outside the organization’s approved baseline.

    3. Two Supply Chain Threats

    These failure modes lead to two categories of supply chain threats in agentic coding. The discussion below concerns their meaning and impact, not exploitation procedures.

    Exposure to Known Vulnerabilities in Outdated Components

    Version ghosts can repeatedly steer builds toward components with publicly known vulnerabilities. An attacker does not need to discover a new flaw if an automated pipeline delivers an affected component into an accessible service, batch job, or desktop tool.

    Potential impacts include remote code execution, sensitive data disclosure, privilege escalation, and contamination of downstream artifacts through build plugins.

    The agent may interpret a successful installation as evidence that its task is complete. If vulnerability scanning is not a blocking condition, the affected component can remain locked into the project for a long time.

    Targeted Poisoning of Hallucinated Package Names

    Name ghosts create potentially predictable gaps in package identifiers. If an external registry permits someone to publish under such a name, a later agent run or a human retry may install that package.

    A poisoned package can perform unexpected actions through installation scripts, import-time initialization, or build plugins, and can propagate through downstream dependencies.

    Unlike conventional typosquatting, the incorrect name does not necessarily come from a human typing error. It may originate from a recurring model hallucination and appear across multiple projects and tasks, creating a repeatable pattern that could be exploited at scale.

    It is important to distinguish a failure mode from a security incident. When a name does not exist, installation failure is usually an availability problem. If the name is claimed by an attacker, or an outdated component with known vulnerabilities is automatically installed, the issue becomes a supply chain security concern.

    Governance should intercept hallucinated names before installation and block unacceptable outdated versions before merge.

    4. Why Prompts Alone Are Not Enough

    A system prompt that says “use current versions” or “do not invent package names” may reduce the likelihood of errors, but it is not an enforceable control.

    Model output varies. As context grows, task objectives may override earlier constraints, and an agent may revise a manifest it created during an earlier reasoning step. A prompt has neither cryptographic enforcement nor the authority of a policy engine. It also cannot establish that a package exists in a registry, that its maintainer is trusted, or that its version has not been withdrawn.

    The appropriate division of responsibility is straightforward: the model proposes candidates; the policy engine can reject them.

    Rejection must happen before lockfile updates and installation. The same controls must apply to commands, scripts, and subprocesses invoked by the agent.

    5. Governance Principles and Practical Controls

    5.1 Limit the Agent’s Authority Over Dependencies

    Establish an approved component baseline for each repository. Define permitted namespaces, prohibited installation sources, and version-pinning requirements.

    Agents may propose new direct dependencies, but those proposals should become reviewable changes rather than immediate installations. Prefer approved internal components where possible, instead of repeatedly adding external packages with overlapping functionality.

    Apply least privilege to the execution environment:

    • Deny access to public registries by default.
    • Allow access only to organization-managed artifact repositories or proxy caches.
    • Use read-only tokens for installation commands.
    • Prevent writes outside the workspace.
    • Restrict outbound network access to approved domains or repository addresses.

    These limits prevent an agent from fetching content from untrusted sources even if it invents a package name.

    5.2 Validate Existence, Source, and Version Before Installation

    Existence validation. Query the trusted registry for the proposed package name and version. Confirm that the package coordinates exist, and record the resolution time and content digest.

    If the query fails, block installation. Do not let the agent substitute a similar name without human approval. Similar names should themselves be treated as a risk signal requiring review.

    Source validation. Dependencies must come through the organization’s proxy or a registered upstream source. Do not allow ad hoc mirror additions.

    Verify lockfile integrity digests, signatures, or equivalent content-addressed identifiers during installation. A proxy cache can retain verified artifacts to reduce repeated downloads, but a cache miss must never bypass policy.

    Version validation. Check direct and transitive dependencies against known vulnerabilities. Publicly disclosed vulnerabilities that are reachable and unmitigated should block merging by default.

    Version selection must follow the baseline:

    • Prefer approved version ranges.
    • Do not float to an unevaluated major release.
    • Do not install without a lockfile.

    If an agent chooses an outdated version, the policy should select an approved fixed version within the baseline or require human review—not accept the first version the model can install.

    5.3 Put Human Approval at Non-Bypassable Gates

    Require review for changes such as:

    • New direct dependencies.
    • Changes to dependency sources.
    • Changes to installation scripts or build plugins.
    • License changes.
    • Maintainer changes or repository migrations.

    Review material should include, at minimum, the package name, version, intended use, baseline status, vulnerability scan results, license, and number of transitive dependencies.

    An agent’s statement that “I checked it” is not a substitute for a scan report.

    Low-risk patch updates may qualify for automatic approval, but the rules must be defined in advance and each approval must leave a machine-verifiable record. Components involving severe vulnerabilities, installation-time scripts, native extensions, or credentials should not qualify for automatic approval.

    5.4 Use SBOMs, Reproducible Builds, and Runtime Restrictions

    Generate a software bill of materials (SBOM) for every build. Record direct and transitive dependencies, versions, digests, sources, and licenses. Archive the SBOM with the lockfile so that each release can be traced to its actual dependency resolution.

    Use clean, immutable dependency caches in build environments to prevent agents from inadvertently relying on old packages left on a developer’s machine.

    Controls must continue at runtime. Even after a successful build, containers and hosts should restrict unnecessary package installation capabilities so that agents or applications cannot fetch new dependencies during execution.

    Emergency fixes should use a separate controlled process: validate the version and digest in a controlled environment, then update the baseline. Avoid ad hoc installation on production hosts.

    5.5 Monitor Hallucination Patterns and Update the Baseline

    Track rejected package names, outdated versions replaced by policy, and recurring near-match spellings.

    If a hallucinated name appears repeatedly, explicitly deny it in policy and check whether a package with that name has appeared in an external registry. Maintain both recommended and permanently denied components in the internal baseline so that later tasks can retrieve them.

    This is more reliable than repeatedly revising prompts.

    Audit logs should include:

    • The user’s objective.
    • The agent’s proposal.
    • The policy decision.
    • The actual installed package coordinates.
    • The operator or automation identity.
    • The timestamp and pipeline identifier.

    Logs support investigation and traceability; they do not replace preventive controls.

    6. An Executable Control Skeleton

    The following pseudocode illustrates control order without assuming a particular product interface. Teams can implement equivalent gates using their existing package managers, artifact repositories, and pipelines.

    1. candidate_dependency = name and version proposed by the agent
    2. if candidate_dependency is not in the baseline and lacks human approval:
    3. reject installation and record the reason
    4. if the coordinates do not exist in the trusted registry:
    5. reject installation
    6. prohibit automatic substitution with a similar name
    7. if the source is not in the approved repository list:
    8. reject installation
    9. if integrity digest or signature verification fails:
    10. reject installation
    11. if vulnerability policy requires blocking:
    12. reject the merge
    13. provide an available version within the baseline or require human review
    14. else:
    15. write lock information
    16. install through the proxy
    17. generate the software bill of materials

    A declarative policy can express team requirements for the pipeline to enforce, rather than leaving the model to interpret them at runtime.

    1. dependency_policy:
    2. default: deny
    3. allow_namespaces:
    4. - internal
    5. require_lockfile: true
    6. allow_install_scripts: false
    7. block_on_known_vulnerability: high
    8. human_approval:
    9. - new_direct_dependency
    10. - source_change

    This illustrative policy denies by default, permits only internal namespaces, requires a lockfile, disables installation scripts, blocks high-severity known vulnerabilities, and requires human approval for new direct dependencies and source changes.

    Thresholds and severity levels should reflect the organization’s risk tolerance. The underlying principle—default denial with approved exceptions—should remain intact.

    7. Where Controls Belong in the Development Lifecycle

    Requirements. State dependency constraints explicitly: whether external network access is permitted, whether new external components are allowed, which licenses are prohibited, and which internal libraries must be reused. Earlier constraints leave less room for uncontrolled agent choices.

    Implementation. Require the agent to submit a dependency proposal before changing application code. If the proposal is not approved, it should not continue generating code around that component. Otherwise, teams may feel pressured to approve a package because the implementation already depends on it.

    Integration. Treat lockfiles and SBOMs as the source of truth. If installation succeeds locally but fails in the pipeline, follow the pipeline decision and investigate whether the local environment used an untrusted cache.

    Release. Compare the built artifact against the source-controlled lock information to detect version overrides introduced through build parameters.

    Runtime. Retain alerts for component hashes outside the baseline. If one is detected, block release or roll back as appropriate.

    8. Common Implementation Mistakes

    Scanning Only Direct Dependencies

    Version ghosts often hide in transitive dependencies. Policy must cover the complete resolved dependency graph.

    Treating Installation Failure as Security Success

    A failed installation only shows that the current registry lacks the requested name. If the agent can switch sources or retry with another name, the gap can still be filled.

    Substituting “Latest” for “Approved”

    The newest version is not necessarily evaluated or compatible. The baseline should consist of versions checked for vulnerabilities, licensing, and compatibility.

    Giving Agents the Same Release Permissions as Developers

    Separate identities that modify dependencies, create release tags, and publish artifacts. Automation identities should use short-lived credentials.

    Documenting Decisions After the Fact

    Without a recorded decision before installation, teams cannot reliably distinguish an intentional dependency choice from a model hallucination. That undermines auditing.

    9. Conclusion

    Agentic coding turns intent into runnable changes quickly. Supply chain security ensures that the components in those changes are explainable, verifiable, and removable.

    Ghost dependencies expose an important distinction: frequent patterns in model memory are not an engineering baseline, and plausible package names are not proof of real projects in a registry.

    Mapping version ghosts to exposure from outdated components, and name ghosts to hallucinated-name poisoning, makes the control points clear:

    • Limit dependency decision authority.
    • Validate existence, source, integrity, and vulnerability status before installation.
    • Require human approval for exceptions.
    • Preserve SBOMs and audit records for traceability.

    Organizations do not need to reject agent-written code. They should reject dependency selection and installation performed on their behalf without an enforcing policy engine.

    Separating proposal, policy decision, installation, and archiving turns agent speed into reliable engineering capability rather than a supply chain shortcut around review.