Files
pmg/README.md
T
648adcbda4 feat: add uvx (uv tool run) package executor (#357)
* feat(uvx): add uvx (uv tool run) package executor

Adds support for `uvx`, implemented as a PyPI Executor alongside pipx.
uvx is an alias for `uv tool run`: it installs a tool into an ephemeral
environment and runs it, so it has no install/list subcommand and the
first positional argument (or --from) is the package to audit.

Parsing highlights:
- --from overrides the positional command as the package to audit
- --with packages are audited as additional environment dependencies
- name@version shorthand (ruff@0.3.0, ruff@latest) is normalized
- flag parsing stops at the tool name so the tool's own flags are not
  misread as uvx options; uvx's value/boolean flags are registered so
  none greedily consume the package positional
- VCS/URL/local-path specs are skipped for registry auditing

Wires up command registration, analytics, shell alias/shim, cloud audit
mapping, a dedicated `uvx` sandbox profile (UV_*/PIP_* env, uv cache and
tool dirs), config policy, docs, unit tests and an E2E workflow step.

Closes #326

https://claude.ai/code/session_011hyLxq7oWJX5Dp4tCEfG19

* chore(uvx): align docs and base profile with uvx support

Incorporates the low-risk, non-parser improvements from the community
PR #345 (author non-responsive) into our implementation:

- list uvx (and the previously-missing pipx) as PyPI managers in the
  pypi-restrictive base profile package_managers and its README, so the
  base profile applies directly when selected via --sandbox-profile
- document uvx in docs/github-action.md and docs/proxy-mode.md
- add version / IsExplicitVersion assertions to the uvx parser tests

Our pflag-based parser is kept as-is: unlike #345 it audits --with
packages and handles all uvx short flags (e.g. -w), both of which the
community PR misses.

* fix(uvx): skip interpreter requests; use require in tests

Addresses review feedback on PR #357:

- uvx interpreter requests (`uvx python`, `uvx python@3.12`, `uvx pypy`,
  ...) launch an isolated interpreter rather than installing a PyPI tool.
  Treating the positional as a package made the guard flow resolve/analyze
  pkg:pypi/python (and python==3.12), which could wrongly block or fail a
  valid invocation. Skip these for the positional; --with packages on the
  same command are still audited.
- Use require.NoError / require.Len for fatal assertions in the uvx tests,
  matching the repo's testing convention, so a failure stops the subtest
  before a nil dereference instead of panicking.

* docs(uvx): document fail-open and --with-requirements trade-offs

Record the two deliberate parsing decisions raised in review as in-code
trade-off comments (no behavior change):

- unknown flags are tolerated (fail open), consistent with the other
  executors; the residual gap only affects non-proxy guard mode since the
  default proxy flow intercepts every registry download.
- --with-requirements / --with-editable values are consumed but not
  expanded into audit targets; expanding them needs manifest-extractor and
  guard changes, tracked as follow-up. Proxy mode still covers them.

* docs(uvx): drop --with-requirements limitation note

Per maintainer review: guard mode is being deprecated and auditing the
contents of an existing requirements file is a scanner's responsibility,
not PMG's. Remove the "known limitation / follow-up" note; the flags stay
registered only so their values are not mistaken for the tool positional.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-02 18:49:31 +05:30

12 KiB

Package Manager Guard (PMG)

Block malicious npm and pip packages before they install.
Defense in depth for the package managers you already use.

safedep%2Fpmg | Trendshift

pmg in action

Docs Website Discord Featured in tl;dr sec

Go Report Card License Release OpenSSF Scorecard CodeQL

Why PMG?

Developers and AI coding agents install packages every day. Each npm install or pip install executes thousands of lines of code that nobody reviews.

Recent compromises in popular ecosystems:

PMG is free, open source (Apache 2.0), and requires no account or API key. It intercepts every package install and checks it against SafeDep's free community API for known malware before code executes. Install it once, and it covers every npm install, pip install, and poetry add after that.

How PMG Works

PMG takes a defense in depth approach. Zero config, works across Zsh, Bash, and Fish, and each install passes through the enabled protection layers before code runs, plus an audit trail after.

PMG defense in depth: install command intercepted by PMG, passed through Layer 1 Threat Intel, Layer 2 Cooldown, Layer 3 Sandbox, then run with an audit log entry
Layer details
  • Transparent Interception - PMG wraps npm, pip, and other package managers. Developers and AI agents use the same commands. No workflow changes.
  • Layer 1: Threat Intelligence - PMG checks every package against SafeDep's real-time threat intelligence before install. Known-malicious packages are blocked. No key, no login required.
  • Layer 2: Policy (Dependency Cooldown) - PMG blocks package versions published inside a configurable cooldown window, so recently compromised versions are skipped during the window.
  • Layer 3: Opt-in Sandbox - When sandboxing is enabled and configured, PMG runs installs inside OS-native sandboxes (macOS Seatbelt, Linux Landlock by default, or Bubblewrap fallback) so install scripts have restricted system access even if a threat slips past the first two layers.
  • Audit Logging - PMG logs every install (what, when, from where) for a verifiable audit trail.

How PMG Compares

PMG is the only free, open-source, install-time package firewall that covers developers and AI agents alike and ships with sandboxing and cooldown out of the box.

Capability PMG Socket safe-chain Snyk Dependabot
OSS / built in public
No account or API key
Install-time malicious package blocking
Dependency cooldown policy
Runtime sandboxing
Protects AI coding agents transparently
Local audit logs
Known-CVE remediation PRs

Quick Start

1. Install

curl -fsSL https://raw.githubusercontent.com/safedep/pmg/main/install.sh | sh

See Installation for Homebrew, npm, and other install methods.

2. Setup

Wire PMG into your shell so it intercepts package managers.

pmg setup install
# Restart your terminal to apply changes

Tip: Re-run pmg setup install after upgrading PMG to pick up new configuration options.

Validate your installation and verify protection is working:

pmg setup doctor

Optional: PMG inspects HTTPS traffic with an on-the-fly CA that it injects into package managers per run. To persist a single CA across runs and trust it in your OS trust store (needed for tools that ignore CA environment variables, such as Go on macOS and Windows), install it once:

pmg setup cert install          # user scope, no sudo
pmg setup cert status           # check trust state and expiry

See Certificate Authority for scopes, rotation, and removal.

3. Use

See PMG blocking threats.

npm install --no-cache --prefer-online safedep-test-pkg@0.1.3

Note: safedep-test-pkg is a benign test package flagged as malicious in SafeDep's database for testing and verification purposes.

Continue using your package managers as usual, or let your AI coding agent run them. PMG sits in the path, blocking malicious packages.

npm install express
# or
pip install requests

Supported Package Managers

PMG supports the tools you already use:

Ecosystem Tools Command Example
Node.js npm npm install <pkg>
pnpm pnpm add <pkg>
yarn yarn add <pkg>
bun bun add <pkg>
npx npx <pkg>
pnpx pnpx <pkg>
Python pip pip install <pkg>
pipx pipx run <pkg>
poetry poetry add <pkg>
uv uv add <pkg>
uvx uvx <pkg>

Installation

Install Script (MacOS/Linux)

Downloads the latest release from GitHub, verifies its SHA-256 checksum, and installs to $HOME/.local/bin (if on PATH) or /usr/local/bin.

curl -fsSL https://raw.githubusercontent.com/safedep/pmg/main/install.sh | sh
Homebrew (MacOS/Linux)
brew tap safedep/tap
brew install safedep/tap/pmg
NPM (Cross-Platform)
npm install -g @safedep/pmg

Note: NPM-based installs can be fragile when Node.js is managed by version managers like mise or asdf. The global npm bin path changes with the active Node version, so switching versions can leave pmg unavailable on PATH (or pointing to an old install). For these setups, prefer the install script or Homebrew.

Go (Build from Source)
# Ensure $(go env GOPATH)/bin is in your $PATH
go install github.com/safedep/pmg@latest
Binary Download

Download the latest binary for your platform from the Releases Page.

GitHub Actions

Protect CI workflows with one step. PMG analyzes every npm install, pip install, etc. in the job.

- uses: safedep/pmg@v1
  with:
    server-mode: true

# intercepted via HTTP_PROXY automatically
- run: npm ci

- name: Enforce PMG policy
  if: always()
  run: pmg proxy stop --fail-on-violation   # stops the daemon, fails the job on a block

By default you get malware blocking and dependency cooldown. Sandbox isolation is opt-in via the sandbox input. Tune behavior via inputs (paranoid, sandbox, cooldown-days, ...) or point config-file at a YAML in the repo. See docs/github-action.md for the full reference.

Uninstallation

Remove shell integration:

pmg setup remove

To also remove the PMG configuration file:

pmg setup remove --config-file

Then uninstall PMG itself:

# Homebrew
brew uninstall safedep/tap/pmg

# NPM
npm uninstall -g @safedep/pmg

Trust and Security

PMG builds are reproducible and signed.

  • Attestations: GitHub and npm attestations guarantee artifact integrity.
  • Verification: You can cryptographically prove the binary matches the source code.
  • See Trusting PMG for verification steps.

User Guide

Support

If PMG saved you from a bad package, star this repo. It helps others find it.

Star History

Star History Chart

Contributing

Contributions welcome. See CONTRIBUTING.md for build and test instructions.

Thank you to all contributors ❤️

Contributors to PMG

Telemetry

PMG collects anonymous usage data. To disable, either:

  • Set disable_telemetry: true in your PMG config file, or
  • Export PMG_DISABLE_TELEMETRY=true.