Skip to main content

Buckthorn

See what a package runs before you install it.

Static checks for Python and npm packages, MCP configs and Hugging Face remote code.
Nothing is installed, imported or run.

License MIT Python 3.11+ Status 0.1 preview Code it runs: none

$ buckthorn scan colourful_logs-1.4.2-py3-none-any.whl
colourful_logs-1.4.2-py3-none-any.whl: flagged
  high     BKT-HIDE-001     colourful_logs/__init__.py:2  exec of data decoded by base64.b64decode
  medium   BKT-PTH-001      colourful_logs-1.4.2.pth:1  .pth line runs code at every Python start

1 scanned: 1 flagged

A package can run code the moment you install it, every time Python starts, or as soon as you import it. Buckthorn reads that code first, straight from the wheel, sdist or npm tarball, and tells you what it does.

What it is for

A quiet CI gate. buckthorn check uv.lock reads every pinned file before anything is installed. On packages it had never seen, it raised about a quarter of GuardDog's false alarms (numbers below).

Upgrades. buckthorn diff requests==2.32.3 requests==2.32.4 shows only what the new version adds. If a maintainer account is taken over, the new code is in that diff.

Your agent's MCP config (preview). An agent starts every server in .mcp.json with your credentials, and uvx some-server pulls whatever was released that day, dependencies included. buckthorn check .mcp.json reads that install set.

Install

Needs Python 3.11 or newer.

pipx install buckthorn      # or: pip install buckthorn
uvx buckthorn --help        # or run it without installing
buckthorn scan pkg-1.2.0-py3-none-any.whl          # one wheel or sdist
buckthorn scan ./dist                              # a folder of them
buckthorn scan left-pad-1.3.0.tgz                  # an npm tarball (preview)
buckthorn check uv.lock                            # every pinned dependency
buckthorn check package-lock.json                  # the same for npm (preview)
buckthorn check .mcp.json                          # an agent's MCP servers (preview)
buckthorn diff requests==2.32.3 requests==2.32.4   # only what an upgrade adds
buckthorn scan --format json ./dist                # machine-readable
  • check reads requirements.txt with hashes, uv.lock and poetry.lock, and package-lock.json (preview).
  • check and diff fetch from PyPI over https only (pypi.org and files.pythonhosted.org), and check each file's sha256 before reading it.
  • By default check reads the file this machine would install for each package. --all-files reads every platform's.

What the verdict means

Verdict Meaning
clean Nothing flagged in what runs at install, at start-up or at import. Code that only runs when you call it is not read, so clean is not "safe".
flagged At least one finding above info. Read it, then fix or accept it.
not_verified Something could not be read. Never reported as clean.

Exit codes: 0 clean, 1 flagged or not_verified (--allow-not-verified lets not_verified pass), 2 a usage or input error.

In CI

The GitHub Action checks a lockfile before anything is installed. It fails the build on a finding and writes SARIF for code scanning:

permissions:
  contents: read
  security-events: write   # for the SARIF upload

steps:
  - uses: actions/checkout@v4
  - uses: hedgerow-dev/buckthorn@v0.2.0
    with:
      lockfile: uv.lock
  - uses: github/codeql-action/upload-sarif@v3
    if: always()
    with:
      sarif_file: buckthorn.sarif
  • Python version. The check reads the files pip would pick for your project's Python: the repository's .python-version, or 3.12 when there is none. Set python-version if your project installs with another one.
  • Pin by SHA. Tags are shown here for reading. For a security check, pin each action to a commit SHA instead, as action.yml does for its own steps.
  • All inputs, including allowlist and signed receipts, are in action.yml.

The first run. A real lockfile often has a package or two that does one of these things on purpose, like setuptools' .pth file. Accept what is there today once, then only new behaviour fails the build:

buckthorn check uv.lock --write-allowlist buckthorn-allow.json

Read the file before you commit it, and pass it as the action's allowlist. Each entry is pinned to the version it was found in, so an upgrade that keeps the same behaviour shows up again for review.

Pre-commit. The hook runs whenever uv.lock, poetry.lock or a requirements*.txt changes:

repos:
  - repo: https://github.com/hedgerow-dev/buckthorn
    rev: v0.2.0
    hooks:
      - id: buckthorn-check

How well it works

We tested it on packages it had never seen, with the plan committed before the first scan (PROTOCOL.md). That run used commit c80b090, from before the last fixes in 0.1.0.

On unseen packages Buckthorn GuardDog 3.2.0
Malicious archives flagged (430) 52.3% 68.6%
Benign files flagged (5,723) 5.4% 23.7%
  • Quiet on real projects. Per project, Buckthorn flagged 8.8% of PyPI's ranks 1,001 to 3,000 and 5.4% of recently updated projects. So expect a flag or two on a real lockfile the first time; --write-allowlist is for that.
  • It misses more malware than GuardDog. Most of what it misses runs only when you call a function, like a downloader behind fetch(url). Of 50 misses we looked at, only one was install, start-up or import code a rule should have caught. In our view it works best next to a feed of known malware, such as OSV's malicious-packages data, and a broader scanner.
  • Real npm takeovers (preview). On Shai-Hulud it flagged 790 of 810 hijacked releases it had never seen, and diff against the version before points at the payload itself. On 588 other npm takeovers it flagged 339: most misses add a malicious dependency rather than change the package. The run found one gap (binding.gyp commands), now fixed: 376 with the fix. Details in eval/real-attacks/RESULTS.md.
  • Tuning data is not the headline. On the corpora we tuned on, it flags about 90% of pypi_malregistry and 85% of DataDog's malicious PyPI samples. The rules were written against that data, so those numbers say less.

The full write-up is in eval/heldout/RESULTS.md.

BUCKTHORN_CALL_TIME=1 also reads code that only runs when called, and flags five combinations, such as fetching code and running it. It is off by default, because it has not been tested on unseen data yet.

Also in preview

An agent's MCP config

An agent starts every MCP server in its config as soon as it loads it, with your credentials, and nobody looks at what uvx some-server pulls in that day. Point check at the config:

buckthorn check .mcp.json                      # Claude Code
buckthorn check .vscode/mcp.json               # VS Code
buckthorn check ~/.cursor/mcp.json             # Cursor (Windsurf and Claude Desktop too)
  • For each server launched with uvx, uv run --with or pipx run, it fetches the PyPI release that would run and scans it, then every package that uvx or pipx would install with it.
  • Dependencies come from the release's static metadata (Requires-Dist), never from installing or building the package.
  • A dependency with no exact version pin is counted in the summary: the newest match was checked, and a later release is what the next start installs. Servers with no version pinned are counted too.
  • npm and Docker servers are reported as not checked yet.
  • Values from env, arguments and URLs are never printed.

npm packages

scan reads npm tarballs too: the .tgz the registry serves, or what npm pack writes.

npm pack left-pad@1.3.0 && buckthorn scan left-pad-1.3.0.tgz

It reads the scripts in package.json, the JavaScript that preinstall, install and postinstall run, and the code that runs when the package is loaded.

check reads package-lock.json and npm-shrinkwrap.json (lockfile version 2 or 3). Each tarball is fetched from registry.npmjs.org only and checked against its sha512 integrity before it is read. An entry with no resolved URL is fetched from there by name and version. Git, local and other-registry sources are reported as not checked. The Action and the pre-commit hook take these files too.

npm support is newer than the Python side: it was tuned on the top 1,000 npm packages and 200 malicious ones, and has not been tested on unseen packages. The rules are the BKT-NPM-* ones in docs/rules.md.

Model repos with remote code

trust_remote_code=True runs the model repo's own Python when you load it. Buckthorn reads that code first: the files auto_map names, what they import, and the methods transformers calls while loading (__init__, post_init, _init_weights and the rest). This part is new, and we have not published an evaluation on real repos yet.

buckthorn hf org/name@<commit>     # fetch config and code only, never weights
buckthorn hf org/name              # reads main today, tells you its commit
buckthorn scan ./my-model          # a downloaded repo or a Hub cache snapshot

hf talks to huggingface.co only, fetches by commit and checks each file against the Hub's blob id. Pin that commit in from_pretrained(revision=...), since a verdict for one commit says nothing about the next. forward and generate run only when you call them, so they are not read. Rules are in docs/rules.md; how this could plug into Hayward is in docs/hf-remote-code.md.

Reference

Accepting a finding

Some real packages do what Buckthorn looks for on purpose: setuptools and coverage.py install .pth files that run at start-up. Once you have looked at one, record it in an allowlist and pass --allowlist allow.json:

{
  "allow": [
    {
      "rule": "BKT-PTH-001",
      "package": "setuptools",
      "file": "distutils-precedence.pth",
      "reason": "setuptools' distutils shim; reviewed 2026-11-03"
    }
  ]
}

rule, package and reason are required. file is a glob, matched with the version folder taken out (*/setup.py matches pkg-2.0/setup.py), and version pins the entry to one release. Allowed findings leave the verdict but stay in the JSON report with their reason. Coverage gaps (BKT-SKIP-*, BKT-LOCK-002) cannot be allowed: they mean something was not read.

For an npm tarball, package is the name in the file name. The registry names @scope/pkg as pkg-1.0.0.tgz, so an entry for pkg also covers another scope's pkg. Pin version to keep it narrow.

Output formats

--format text (default), json, or sarif for GitHub code scanning.

The JSON report carries a schema_version. It goes up when a key changes meaning or is removed. New keys can appear in any release.

Scan receipts

--receipt FILE also writes an unsigned in-toto statement: each artifact's sha256 and what Buckthorn found in it, taken before --allowlist. It has the same shape as Hayward's receipts. It is analysis evidence, not a safety certificate. In GitHub Actions, set the action's receipt and attest: "true" inputs to have GitHub sign it with Sigstore.

For coding agents (MCP server)
pip install "buckthorn[mcp]"
buckthorn mcp

A stdio MCP server with three read-only tools, all returning the same JSON as --format json:

  • scan_path: a wheel, sdist or folder of them, no network.
  • check_release: a PyPI name and version. The file this machine would install, fetched and hash-checked as check does.
  • check_mcp_config: the text of an MCP config, checked as check does.

Every rule is listed in docs/rules.md, and the design is in SPEC.md.


Buckthorn is MIT licensed and part of Hedgerow, next to Hayward for model files.

Metadata

Release files for buckthorn 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for buckthorn 0.2.0
File Size Uploaded Provenance Actions
buckthorn-0.2.0.tar.gz 235.3 kB With provenance Details for buckthorn-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for buckthorn 0.2.0
File Interpreter ABI Platform Actions
buckthorn-0.2.0-py3-none-any.whl Python 3 none any Details for buckthorn-0.2.0-py3-none-any.whl

Total release size: 367.4 kB

Release files / buckthorn-0.2.0.tar.gz

Download URL buckthorn-0.2.0.tar.gz
Size 235.3 kB
Tags Source
SHA-256 checksum
How to use checksums
338561151fc3d1d2881b8b1c02c83299259dfe4f5f5b3c2febee7da9a2546fc6
BLAKE2b-256 checksum
How to use checksums
9012fe168d60a3aee674fae97f6160c122b68dc3bc2e675711023eb20cca9e52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / buckthorn-0.2.0-py3-none-any.whl

Download URL buckthorn-0.2.0-py3-none-any.whl
Size 132.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df662789c2dfccbd5f267ffa117c478ab85bdce65f0ad88cf133df21b8cb1f1a
BLAKE2b-256 checksum
How to use checksums
b440fe0302f0410ed4ed011032f50c7bd4871ef6d61f5d73917a56e4d12b18e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for buckthorn 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for buckthorn-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page