Skip to content

Automatic hooks — enforce checks even when the agent forgets

The MCP tools cover the agent path (prompt/skill from Desktop apps and Agent setup). For everything else, wire Soverenia as a hook so every install is checked automatically — all paths produce the same signed verdict (SAFE / UPGRADE / AVOID), verifiable against /.well-known/soverenia-keys.json.

All CLI paths come from @soverenia/agent-guard (npm install -g @soverenia/agent-guard provides the soverenia-mcp and soverenia-scan binaries). Configuration, in order of precedence:

  1. env SOVEREENIA_API_KEY (required) and SOVEREENIA_BASE_URL (default https://www.soverenia.com)
  2. ~/.soverenia.json — {"apiKey": "sov_…", "baseUrl": "https://…"} (env wins over the file)

1. soverenia-scan — CI gate on lockfiles

soverenia-scan [lockfile] [--policy strict|balanced|quiet] [--fail-on avoid|upgrade] [--json] [--sbom auto|always|never] [--sbom-threshold N]
  • lockfile — optional, default package-lock.json. Supported formats:
  • package-lock.json (npm) — every entry of the packages map under node_modules/ (including nested node_modules/a/node_modules/b)
  • requirements.txt (PyPI) — name==version pins; comments (#) skipped, names lowercased per PEP 503
  • --policy strict|balanced|quiet — verdict policy for every dependency (default balanced; the ladder is in the API reference). In short: strict AVOIDs any no-fix advisory from medium (CVSS ≥ 4.0) up and UPGRADEs on any fix; balanced escalates on high (CVSS ≥ 7.0 or EPSS ≥ 0.5) and additionally on ≥ 2 medium advisories with a fix; quiet only AVOIDs critical (CVSS ≥ 9.0) without a fix or known-exploited — never a silent SAFE on those. upgrade_to on UPGRADE always covers all fixable advisories, not just the triggering one (see upgrade_to_also_fixes in the evidence).
  • --fail-on avoid|upgrade — exit 1 on AVOID (default) or also on UPGRADE (strict CI)
  • --json — machine-readable report on stdout: {file, via, policy, fail_on, total, summary{SAFE,UPGRADE,AVOID,error}, verdicts[]}
  • --sbom auto|always|never and --sbom-threshold N — see SBOM path below

Exit codes: 0 = clean · 1 = fail condition hit (AVOID, or UPGRADE with --fail-on upgrade) · 2 = scan error (no dependencies found in the lockfile, lockfile unreadable, API unreachable, invalid flags — usage is printed to stderr). A malicious or typosquatted dependency therefore fails the PR.

GitHub Actions

# .github/workflows/sovereignia.yml
name: soverenia
on: [pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: 22 }
      - run: npx soverenia-scan package-lock.json --fail-on upgrade --json > soverenia-report.json
        env:
          SOVEREENIA_API_KEY: ${{ secrets.SOVEREENIA_API_KEY }}
      - uses: actions/upload-artifact@v4
        if: always()
        with: { name: soverenia-report, path: soverenia-report.json }

Generic CI (GitLab CI, Jenkins, CircleCI, Azure Pipelines — anywhere Node ≥ 22 runs)

# .gitlab-ci.yml (same idea everywhere — just a shell step with the key in a CI variable)
soverenia:
  image: node:22
  script:
    - npx soverenia-scan package-lock.json --fail-on avoid
    # PyPI projects:
    # - npx soverenia-scan requirements.txt
// Jenkinsfile (declarative pipeline, one stage)
stage('soverenia') {
  steps {
    withEnv(["SOVEREENIA_API_KEY=${SOVEREENIA_API_KEY}"]) {
      sh 'npx soverenia-scan package-lock.json --json > soverenia-report.json'
    }
    archiveArtifacts artifacts: 'soverenia-report.json', allowEmptyArchive: true
  }
}

The SBOM path (large lockfiles)

With the default --sbom auto, a lockfile with ≥ 30 dependencies (--sbom-threshold N to change the threshold) is sent as one check_sbom request — the CLI builds a CycloneDX 1.5 SBOM from the lockfile ({bomFormat:"CycloneDX", specVersion:"1.5", components:[{type:"library",name,version,purl}]}, with ecosystem: npm|pypi as fallback for components without a purl) and gets back summary {SAFE,UPGRADE,AVOID,error} + one verdict per component, served from the server-side cache. --sbom always forces this path, --sbom never disables it.

Two things to know:

  • check_sbom requires the Pro plan. On a free key the SBOM call fails with PLAN_REQUIRED and the CLI falls back to the per-package check_package loop (also on any other SBOM failure) — so free keys still work, but on big lockfiles the fallback can hit the free 60 req/min per-key limit (see rate limits). Pro keys (300 req/min) should use the SBOM path for lockfiles ≥ 30 deps.
  • Errors per package (e.g. PACKAGE_NOT_FOUND) count into summary.error and make the scan exit 2 — "unknown" is never treated as SAFE.

2. git hooks (pre-commit / pre-push)

.git/hooks/pre-commit (same body works for pre-push — just copy the file):

#!/bin/sh
# Scan the lockfiles staged in this commit; exit 1 on AVOID blocks the commit.
LOCKFILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '(^|/)(package-lock\.json|requirements\.txt)$' || true)
if [ -n "$LOCKFILES" ]; then
  npx soverenia-scan $LOCKFILES
fi

(package-lock.json and requirements.txt are the two formats soverenia-scan reads — other lockfiles like go.mod/Cargo.lock are not parsed by the CLI; use the MCP check_install_plan tool or an SBOM upload for those.)

3. npm preinstall hook

Block the install itself in package.json (runs before dependencies are installed — make sure a lockfile exists, e.g. committed):

{
  "scripts": {
    "preinstall": "npx soverenia-scan package-lock.json --fail-on avoid"
  }
}

With a local dev dependency on @soverenia/agent-guard you can drop the npx prefix ("preinstall": "soverenia-scan").

4. Agent at install time

MCP check_package / check_install_plan on https://www.soverenia.com/mcp, enforced via the prompt or skill (see Agent setup).

5. SBOM upload via API (compliance / CRA)

The Cyber Resilience Act makes an SBOM a mandatory output — you can also have Soverenia security-check that exact SBOM in one call and keep the result as evidence:

curl -s -X POST https://www.soverenia.com/v1/check_sbom \
  -H "Authorization: Bearer sov_…" \
  -H "X-Sovereignia-Timestamp: $(date +%s%3N)" \
  -H "X-Sovereignia-Nonce: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"sbom_text": "'"$(jq -c . sbom.cdx.json)"'", "policy": "balanced"}'

Accepts CycloneDX ({bomFormat:"CycloneDX", specVersion, components[]}) or SPDX ({spdxVersion, packages[]}) as a JSON object in sbom or a JSON string in sbom_text; 5 MB body limit; response {sbom:{format,total,checked,skipped[]}, policy, summary{SAFE,UPGRADE,AVOID,error}, verdicts[]}. Pro plan required (403 PLAN_REQUIRED otherwise) — full contract in the API reference. Every verdict is written to the WORM audit log; on Enterprise, GET /v1/verdict_history?purl=…&version=… returns the signed history of any package as deploy-time evidence.


What gets checked per package (registry trust, repository URL, publisher history, name originality/typosquats, license changes, install scripts, lockfile integrity, known vulnerabilities/malware from OSV · GitHub Advisory · EUVD · CISA KEV · NVD · OpenSSF · deps.dev) is summarized on the docs home; every verdict response lists the underlying records with full provenance.