Skip to content
mentoor

Supply chain of an agentic codebase

For engineers

Hallucinated dependencies, vetted MCP servers, security review and CI gates for agent-written code.

The one-sentence idea: an AI coding agent can add a feature, a dependency and a tool connection in one afternoon, and every one of those is a new way for untrusted code to enter your system, so each needs its own check before anything runs.

The case

Lumen Billing is a small fintech team. They ask a coding agent, running in their IDE and in CI, to add PDF export for invoices. The agent writes the endpoint, adds a PDF library, connects an MCP server to read ledger data, and opens a pull request. The tests pass. The change looks finished.

It contains five separate supply-chain risks. Each one maps to a skill from this course.

Why it matters

A supply chain is everything your code trusts but did not write: packages, model files, tool servers, build scripts and the agents that run them. An agent widens that chain fast. It does not hesitate before adding a package, and it can be wrong with confidence. A model can invent a package name. Attackers watch for names models invent, register them, and wait. This is called slopsquatting. A tool server can change its own description after you approve it. A CI agent can run code from a stranger's pull request while holding your secrets.

None of these show up as a failing test.

How to review it, in order

  1. Check every new dependency before install. For each package the agent adds, look at its age, downloads, maintainers and source link. A name that is nine days old with 41 downloads and no repository is not the library the agent meant. Existence on the registry proves nothing.
  2. Vet the MCP server like a dependency. Find who publishes it, what scopes it asks for, and what its tool descriptions say. Pin an exact version. Descriptions are instructions to the model, so a changed description is a behaviour change.
  3. Check the AI parts you load. Model files can run code when loaded, and a loader flag such as remote code execution runs Python from the model repository. Record each model, dataset and tool, with its source, version and signature, in a bill of materials.
  4. Review the code the agent wrote as you would a stranger's. The new endpoint had authentication but no ownership check. The handler built SQL from a string. A live key sat in a diff. Rank the findings against the OWASP Top 10.
  5. Put gates in CI, and keep the CI agent on a leash. Check the lockfile diff against an allow-list before install. Never give a fork's code your secrets. Require a human review the agent cannot bypass. Measure whether the bot helps.

Before and after

Before: the agent runs npm install pdf-invoice-kit, and the review agent writes "exists on npm, verified." The package then runs an install script on every laptop and CI runner.

After: the lockfile diff is checked against the allow-list before any install. The new package fails on age, usage and source link. A person confirms the real library name, and the dependency is added through a reviewed pull request.

What goes wrong

  • Trusting a green build. Tests check behaviour. They do not check where code came from.
  • Trusting the agent's own review. The model that wrote the code will often confirm it is safe. Use signals and gates that do not depend on its opinion.
  • Fixing a red build by weakening it. An agent can make a failing check pass by skipping it or loosening the assertion, which hides the finding.
  • Pinning once and never reviewing. A pinned MCP server can still be upgraded by a person who skips the diff of its tool definitions.

How to practise

Work through the six steps below on the Lumen Billing pull request, then answer the questions. Each question names the skill it builds, so you can see which part of the chain you still miss.

Steps

  1. Check the packages the agent added

    Skill: aicode-hallucinated-deps

    The agent adds three dependencies. Two are long-standing libraries. One, pdf-invoice-kit, was published nine days ago, has 41 weekly downloads and no repository link. Stop there, confirm what library the team actually meant, and add only that one through a reviewed change.

    Registry lookup
    PackageFirst publishedWeekly downloadsRepository link
    pdfkit20111,400,000yes
    pdf-invoice-kit9 days ago41none
  2. Vet and pin the AI parts you load

    Skill: aisec-supply-chain

    The reranker loads a community model with trust_remote_code=True from a floating branch. Switch to a safe weights format, pin a commit, and record the source, version and signature of each model, dataset and tool in a bill of materials.

  3. Review the MCP server before connecting it

    Skill: mcp-vetting

    The ledger MCP server is configured with @latest and asks for payment write access to read invoices. Choose the verified vendor server with read scope, pin an exact version, and diff its tool descriptions on every upgrade.

    .mcp.json (before)

    .mcp.json

    "args": ["-y", "ledger-sync-mcp@latest"]
  4. Review the generated code as a stranger's code

    Skill: eng-security

    Add the ownership check to the PDF endpoint, replace string-built SQL with a parameterised query, and move the committed key into a secret manager. Rotate the key first, because it is already in history.

  5. Gate the pipeline and limit the CI agent

    Skill: sdlc-ci

    Run the allow-list check on the lockfile diff before install. Move the fixer workflow off pull_request_target, drop write permissions, and require a code-owner review that the agent cannot bypass. Do not let it weaken a failing test.

  6. Measure whether the gates and bots help

    Skill: sdlc-ci

    After eight weeks, count the comments acted on, the comments dismissed as wrong and the cost per pull request. Tune what is noisy, keep what finds real issues, and record the decision.

Skills this scenario uses

Where to study