feat(build): lock tool dependencies and keep package code off the network
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
- Domain
- build-system, tooling
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
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:
- 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.
- 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.
- 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.
- 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 itspackage.jsonin the same folder. It's installed withnpm 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.
- Download and check the files with network on and install scripts turned off:
- 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.
- Allow only prebuilt wheels (uv's
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
-
Schema and validation.
- Add
lockFileunderpackage. 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.jsonnext to it. - Fail with a clear message if:
- the file is missing;
- the PyPI lock has no
name==versionline for the pinned package (compare names the way PyPI does: case-insensitive, with-,_and.treated the same); - the npm
package.jsondoesn'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.
- Add
-
PyPI install with a lock file.
uv tool installcan'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'sbininto/opt/agentkit-tools/bin. Fail if it isn't there.
Without a lock file, keep #54's
uv tool install, but add--no-build. - create a virtual environment with
-
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. - Step A, network on:
-
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 withUV_CACHE_DIR;llb.AsPersistentCacheDir("agentkit-npm", llb.CacheMountShared), pointed at withnpm_config_cache.
These mounts never become part of the image.
-
Check the flags against the uv and npm versions in the runtime images (Wolfi
uvandnpm-12, seeruntimes/*/Dockerfile).
Tests
- Go, validation:
- a missing lock file;
- the pinned version not in the lock;
- an npm
package.jsonthat doesn't match; - a path that escapes the build context.
- Go, build steps:
- PyPI steps use
--require-hashesand--no-build; - npm uses two steps, the first with
--ignore-scriptsand 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.
- PyPI steps use
- 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.
- Add fixtures with real lock files, for example under
- 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
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from orka-agents/agentkit
-
fix(pydantic-ai): CI fails with newest pydantic-ai (unexpected 'history' argument)Possibly taken @gambtho claimed this 30 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
orka-agents/agentkit#77 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
orka-agents/agentkit#76 · 3 comments ·
-
area/build area/orka area/runtime blocked enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
orka-agents/agentkit#69 ·
-
area/build area/orka area/runtime enhancement
Difficulty 4/5 3-5 days Newbie friendliness 68/100
orka-agents/agentkit#68 ·
-
area/build enhancement testing
Difficulty 5/5 Over a week Newbie friendliness 42/100
orka-agents/agentkit#65 ·
All issues in orka-agents/agentkit
Similar issues
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
sav-oss-org/ptusa_main#1610 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug status/accepted type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
microsoft/apm#4925 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sagemathinc/sagebrush#1701 ·
Maintainers usually reply within 1 day