feat(build): lock tool dependencies and keep package code off the network

Open
#63 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, go, node.js, python

Research direction

Start with pkg/agentkit/config/tool.go, validate.go, pkg/agentkit2llb/agent/convert.go, and pkg/build/instructions.go; trace how package installs and build-context files are handled. Run the Go validation and build-step tests, then go test ./... and make lint. Done means lock files are validated and affect the build cache, installs follow the network and wheel restrictions, caches stay out of the image, and the docs and end-to-end checks cover the specified behavior.

Written by the indexing model from the issue text.

Description

area/build blocked enhancement security

Depends on #54. #54 installs each stdio tool's package into the image at build time, pinned to an exact version. This issue makes those installs fully locked, safer and faster to rebuild.

Problem

After #54, a tool's own version is pinned, but four gaps remain:

  1. Dependencies are not pinned. The tool's dependencies are picked fresh every time the install step runs. Two builds of the same file a week apart can contain different dependency code. A bad or compromised dependency release slips in without anyone noticing.
  2. Downloads are not checked. Nothing confirms that the downloaded files are the ones you expected. A lock file fixes both of these: it lists the exact version of every dependency plus a hash, a fingerprint of each file. The installer can then refuse anything that doesn't match.
  3. Package code runs with network access. npm packages can run scripts while installing, and Python packages without a prebuilt version (a wheel) run build code. With the network on, that code can download and run more code.
  4. Every rebuild downloads everything again. There's no download cache between builds.

dalec handles this by downloading dependencies in one step with network access, then building in a separate step with the network off (see dalec's generator_pip.go and the Go and Cargo generators). It also keeps download caches between builds (see dalec's caches docs).

What

1. Optional lock file per tool

The lock file is read from the build context:

tools:
  - name: fetch
    package:
      pypi: mcp-server-fetch==<version>
      lockFile: ./tools/fetch/requirements.txt
    command: ["mcp-server-fetch"]

  - name: everything
    package:
      npm: "@modelcontextprotocol/server-everything@<version>"
      lockFile: ./tools/everything/package-lock.json   # package.json must sit next to it
    command: ["mcp-server-everything"]
  • PyPI: a requirements file with hashes, made with uv pip compile --generate-hashes. The install refuses any file whose hash doesn't match.
  • npm: a package-lock.json, with its package.json in the same folder. It's installed with npm ci, which checks every file against the lock file.
  • Must match. The build fails if the lock file doesn't contain the pinned package at the pinned version.
  • Docs. Show the exact commands for creating both kinds of lock file.
2. Package code never runs while the network is on

This applies to every packaged tool, with or without a lock file.

  • npm:
    • Download and check the files with network on and install scripts turned off: npm ci --ignore-scripts.
    • Then run the install scripts in a second step with the network off: npm rebuild.
    • A script that needs the network will fail, and the docs should say so.
  • PyPI:
    • Allow only prebuilt wheels (uv's --no-build). Installing a wheel just unpacks files and runs no package code.
    • If a package has no wheel, fail with a clear message that names the package.
3. Download cache between builds
  • Keep uv's and npm's download caches between builds.
  • After a version bump, only what changed gets downloaded.
  • The cache must never end up in the image.
Out of scope
  • Private package indexes and registries that need credentials. That needs BuildKit build secrets and is still a follow-up.
  • A way to allow Python packages that have no wheel. Add it later if people need it.
  • Plain binary downloads. That's #43.

Why

  • Same file, same tool code. Every build installs the same dependency code, down to the file fingerprint.
  • Tampering is caught. The build fails if a download doesn't match.
  • Package scripts can't fetch more code during the build.
  • Faster rebuilds.

How

Where things are
File What it does
pkg/agentkit/config/tool.go ToolPackage from #54. Add LockFile here.
pkg/agentkit/config/validate.go Tool checks, including the package rules from #54.
pkg/agentkit2llb/agent/convert.go The install steps added by #54.
pkg/build/instructions.go contextFileReader.ReadFile reads files from the build context. Instruction files already use it. Read lock files the same way.
Steps
  1. Schema and validation.

    • Add lockFile under package. The path is relative to the build context, and paths that escape it, such as ../, are rejected. Check how instruction file paths are handled and do the same.
    • When building, read the file. For npm, also read the package.json next to it.
    • Fail with a clear message if:
      • the file is missing;
      • the PyPI lock has no name==version line for the pinned package (compare names the way PyPI does: case-insensitive, with -, _ and . treated the same);
      • the npm package.json doesn't list the pinned package at the pinned version.
    • Pass the file contents into the install step by writing them into an empty filesystem (llb.Scratch().File(llb.Mkfile(...))). That way the build cache notices when a lock file changes.
  2. PyPI install with a lock file. uv tool install can't check hashes, so instead:

    • create a virtual environment with uv venv /opt/agentkit-tools/uv/<tool>;
    • install with uv pip install --python /opt/agentkit-tools/uv/<tool>/bin/python --require-hashes --no-build -r <lock>;
    • link the program named in command[0] from that environment's bin into /opt/agentkit-tools/bin. Fail if it isn't there.

    Without a lock file, keep #54's uv tool install, but add --no-build.

  3. npm install, two steps. Use one folder per tool, for example /opt/agentkit-tools/npm/<tool>.

    • Step A, network on: npm ci --ignore-scripts.
    • Step B, network off (llb.Network(llb.NetModeNone)): npm rebuild.
    • Link the program into /opt/agentkit-tools/bin.

    Without a lock file, use npm install --ignore-scripts <spec> in step A, then the same step B.

  4. Download cache. During the install steps, mount uv's cache directory and npm's cache directory as shared persistent caches:

    • llb.AsPersistentCacheDir("agentkit-uv", llb.CacheMountShared), pointed at with UV_CACHE_DIR;
    • llb.AsPersistentCacheDir("agentkit-npm", llb.CacheMountShared), pointed at with npm_config_cache.

    These mounts never become part of the image.

  5. Check the flags against the uv and npm versions in the runtime images (Wolfi uv and npm-12, see runtimes/*/Dockerfile).

Tests
  • Go, validation:
    • a missing lock file;
    • the pinned version not in the lock;
    • an npm package.json that doesn't match;
    • a path that escapes the build context.
  • Go, build steps:
    • PyPI steps use --require-hashes and --no-build;
    • npm uses two steps, the first with --ignore-scripts and the second with network off;
    • both cache mounts are present;
    • the image contents don't include the caches;
    • a changed lock file changes the step.
  • End to end:
    • Add fixtures with real lock files, for example under test/tool-locks/.
    • The agent builds and starts with docker run --network none.
    • Editing one hash in a lock file makes the build fail.
    • A second build after bumping one version reuses cached downloads.
  • If #61 has landed, add the new install steps to its checks that builds come out the same every time.

Run:

go test ./...
make lint
Docs
  • docs/agentkitfile.md: add a "Locking tool dependencies" section covering:
    • how to create each kind of lock file;
    • the "package code never runs with network on" rule;
    • the wheels-only rule for Python;
    • what to do when a package fails because of either rule.

Done when

  • Tools with a lock file install exactly the locked files, and a tampered hash fails the build.
  • npm install scripts run only with the network off, and Python installs use wheels only.
  • Rebuilds after a version bump reuse cached downloads, and no cache ends up in the image.
  • Agents with locked tools start with --network none.
  • The docs explain how to create lock files and what the new rules mean.
Dominant language
Python
Stars
7
Forks
5
Avg merge
3h 39m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from orka-agents/agentkit

All issues in orka-agents/agentkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.