CLI Usage
The commands the Safeguard CLI actually ships, with the flags they take and what they write
CLI Usage
This page covers the commands you run directly, outside the interactive
terminal. Most people start with the terminal instead: run safeguard, type
/login, then /scan .. See Interactive terminal and
Slash commands.
safeguard --help lists every command in the build you have, and
safeguard <command> --help lists its flags. If this page and --help
disagree, --help is right.
Command structure
safeguard <command> [subcommand] [flags]Sign in
Authentication is an OAuth 2.0 device-code flow. It works the same from the
terminal (/login) and from the command line:
# Opens your browser; approve the session there
safeguard login
# On a machine with no browser: prints a URL and a code to enter elsewhere
safeguard login --no-browser
# Who am I signed in as, and when does the token expire
safeguard whoami
# Revoke the session and remove the local token
safeguard logoutThe token is stored on the machine that signed in. There is no API-key environment variable for the CLI: a machine is authorized by signing in once.
Scan
safeguard scan builds an SBOM for a target, matches it against
vulnerability databases, and writes the results as JSON files under
--output (default ./output). It takes exactly one target:
# A local directory (your own or proprietary code)
safeguard scan --dir .
# A container image
safeguard scan --image nginx:latest
# A private registry
safeguard scan --image myregistry.azurecr.io/myapp:v1 \
--registry-username "$REGISTRY_USER" \
--registry-password "$REGISTRY_PASSWORD"
# A Git repository
safeguard scan --repo https://github.com/org/repo
# A private repository
safeguard scan --repo https://github.com/org/private-repo --git-token "$GIT_TOKEN"
# An SBOM you already have (SPDX or CycloneDX, detected automatically)
safeguard scan --sbom sbom.jsonUseful flags:
| Flag | Effect |
|---|---|
--output <dir> | Where results are written (default output) |
--scanners <list> | Run only these scanners |
--resolve-transitive | Resolve transitive dependencies through deps.dev |
--org-namespace <list> | Namespaces that identify your own private packages, such as @mycompany |
--format auto|spdx|cyclonedx | Format of the SBOM passed with --sbom |
--verbose | More detail while the scan runs |
Results include vuln.json, license.json and collection.json, among
others, in a folder per scan. To see them in the platform alongside your other
projects, scan from the interactive terminal (/scan .) while signed in: the
runner uploads the SBOM and findings, never your source.
safeguard scan uses the CLI's scanner tools: an SBOM generator and a
vulnerability scanner. The interactive terminal downloads them the first time it
runs. On a machine that has never opened the terminal, such as a fresh CI
container, run safeguard setup once before the scan, or point TOOLS_DIR at a
directory that already holds the tools.
Exit codes
safeguard scan does not fail on findings. It exits 0 when the scan ran,
whatever it found, 1 when the command itself failed (a bad flag, an
unreadable target), and 2 when results were written but the vulnerability
scan did not actually run, so a script never mistakes that for a clean pass.
There is no severity threshold flag; gating on findings is done by
policy gates in the platform.
Installers, archives and VM images
Pass a vendor installer, an archive or a VM disk image directly and the CLI opens it before it builds the SBOM, so the components inside are listed and matched without manual extraction and without root. Every installer, archive, image and app type the CLI opens is listed in What Safeguard Can Analyse.
# A Windows installer, a setup program or a ZIP of DLLs
safeguard sbom --dir vendor-setup.exe
safeguard scan --dir vendor-setup.msi
# A VM disk image
safeguard scan --image-file appliance.qcow2What it opens: MSI and CAB, NSIS, 7-Zip and WiX Burn
setup programs, 7z, ZIP, TAR, GZIP, XZ and BZIP2 archives, and OVA, QCOW2,
VMDK, VHD, VHDX and raw disk images (partition table, then ext2, ext3, ext4,
NTFS and FAT). Windows programs and .NET libraries inside carry the name,
version, supplier and hashes read from the file itself. Each input prints one
summary line: the detected type, how it was opened and how many files came out,
or "opaque, not unpacked" with the reason, for example an Inno Setup program or
an XFS or LVM disk. Components record where they came from, such as
setup.exe > core.msi.
| Flag or variable | Effect |
|---|---|
--unpack auto|on|off | auto (default for a single file or --image-file) opens installers and disk images; on also opens ZIP and TAR archives in a folder; off turns it off |
SAFEGUARD_UNPACK_MAX_GB | Size budget for large VM images, 1 to 4096 (default 24) |
SAFEGUARD_UNPACK_TIMEOUT_MINUTES | Time limit, 1 to 1440 (default 45) |
SAFEGUARD_7ZIP | Path to a 7-Zip 26.05 or later binary |
Measured time, memory and disk space for 20 GB QCOW2, VMDK and OVA images, with the settings used, are on Large VM Images.
safeguard setup installs a pinned, checksum-verified 7-Zip 26.05 next to the
other scanner tools; scans never download it. Without it, installers and disk
images are listed as not opened and the scan continues. Keep free disk space
on the temporary folder equal to the virtual size of the partitions the image
opens. Operating system packages inside a VM image are matched with their
distribution context, and the result is reported with the source
unpacked-sbom-scan.
If no vulnerability matcher could run (no database or no scanner binary), the
scan prints vulnerabilities not assessed, records
vulnerabilities_assessed: false in collectionsummary.json and exits 2,
rather than reporting zero (unless --scanners narrowed the set).
Find secrets and misconfigurations
# Secrets and misconfigurations in the current directory
safeguard detect
# Only secrets, as SARIF, written to a file
safeguard detect --detect secrets --format sarif --output detect.sarif
# Only report high and critical
safeguard detect --severity high--format takes table (default), json or sarif. Values are redacted in
the output unless you pass --redact=false.
Validate an SBOM
safeguard validate sbom.json
safeguard validate ./sboms --recursive
safeguard validate sbom.json --strict -o report.jsonIt checks CycloneDX (JSON and XML), SPDX (JSON, YAML, tag-value and RDF) and
VEX (CSAF and OpenVEX) documents against their specifications. --strict
treats warnings as errors, and --fail-fast stops at the first error.
Fix and review
# Plan dependency upgrades for the vulnerabilities in a scan result
safeguard fix --dry-run --scan-result vuln.json --manifest package.json
# Review the working-tree changes for correctness and security
safeguard review --help
# Run the assistant non-interactively, for example in CI
safeguard exec "summarise the critical findings in this repository"safeguard fix works out which upgrades would remove each vulnerability and
writes that plan as a report. It does not edit your manifest: applying the
upgrades is not implemented in the CLI today, so make the version changes
yourself or use Safeguard's remediation in the platform. The safeguard report
command is also not implemented yet, so use the scan output files and the
platform's reports instead.
safeguard exec runs one agent turn and exits. Its default permission mode is
strict: nothing is asked and anything the policy file has not pre-approved is
denied. It refuses to run outside a git repository unless you pass
--skip-git-repo-check. --output-format json gives a machine-readable
result. --permission-mode (-a) accepts supervised, edits, plan, guarded,
strict or autonomous; autonomous is refused outside a sandbox unless --dangerously-skip-permissions (alias --yolo) is passed.
Keep it current
# Refresh the scanners' vulnerability databases
safeguard update
# Import a signed vulnerability database bundle
safeguard update --scanner grype --import db.tar.gz --signature db.tar.gz.sig \
--checksum sha256:<hex>
# Update the safeguard binary itself
safeguard self-update
# Check whether a new release exists without installing it
safeguard self-update --checkSigned database bundles
safeguard update --import (and GRYPE_DB_IMPORT_PATH) imports an archive only
when its signature verifies and its checksum matches. By default the signature
is checked against the Safeguard public key built into the CLI, published at
https://registry.safeguard.sh/_gold/keys/cosign.pub; the signature file is
<archive>.sig and the checksum file is <archive>.sha256. If you run your
own mirror, sign it with your own key and import with --key. A missing or
invalid signature, or a checksum mismatch, refuses the import and exits with a
non-zero status, so a script stops instead of scanning with the old database.
# Sign an archive into a bundle with your own key
safeguard update --scanner grype --export-bundle ./bundles --from db.tar.gz \
--sign-key signing.pemThe archive is read once into a private copy and checked on exactly those
bytes, so a file changed after the check is never imported. Allow free disk
space for one extra copy of the archive beside the database. An archive
downloaded straight from the upstream database project is not signed by
Safeguard: check its checksum, sign it with your own key and import it with
--key. Signatures use the cosign sign-blob --key format (ECDSA P-256).
Check the installation
safeguard doctordoctor checks the environment, sign-in, tools and policy, and prints what
is wrong in the order that matters. It changes nothing and exits 0 whenever
the checks ran, so read its lines rather than its exit code.
Ask for help
safeguard support ask "how do I scope a DAST scan to one host?"
safeguard support bug "the scan reported zero findings on a repo with known CVEs"
safeguard support feedback "the findings table should remember my filters"
safeguard support list
safeguard support show SUP-7KQ4-M2XD
safeguard support reply SUP-7KQ4-M2XD "it happens on every scan of that repo"These raise the same tickets as the product's Help & Feedback sheet, and you
follow them in the app's Messages › Support too. You need to be signed in.
--priority low|normal|high|urgent sets the urgency (default normal), and
--yes answers the confirmation in advance. In the interactive terminal,
/bug, /feedback and /support do the same. See
Help and support.
Podman
safeguard podman lists and scans the images in a Podman store through the Podman REST API. No Docker and no inbound connection are needed. Run it on the Podman host as the user that owns the images (rootless) or as root (rootful). Start the API socket first with systemctl --user enable --now podman.socket.
safeguard podman ping # finds the socket and shows the Podman version
safeguard podman images [--all] [--json] # every image with its ID and digest
safeguard podman containers [--all] [--json] # containers with the digest of the image they run
safeguard podman inventory [--json] # running containers grouped by image digest
safeguard podman scan <image>... # scan named images by image ID
safeguard podman scan --running # the images of running containers
safeguard podman scan --all [--json] [--keep ./scans]scan reads each image one of three ways: --via api (default) exports it over the API as an OCI archive, --via syft hands podman:<id> to the CLI's SBOM generator (local socket only), and --via save runs podman image save. --format docker-archive changes the archive format. Results stay on the machine.
The socket is found like podman --remote: --url, CONTAINER_HOST, $XDG_RUNTIME_DIR/podman/podman.sock, /run/user/<uid>/podman/podman.sock, then /run/podman/podman.sock. For another host use --url ssh://<user>@<host>/run/user/<uid>/podman/podman.sock with --identity <key> (or CONTAINER_SSHKEY, or ssh-agent; CONTAINER_PASSPHRASE for an encrypted key) and --known-hosts <file> (default ~/.ssh/known_hosts). Host keys are always checked. For mutual TLS (Podman 5.7 or later) use --url tcp://<host>:<port> --tls-ca ca.pem --tls-cert client.pem --tls-key client-key.pem.
safeguard scan --image also reads local images: podman:<ref>, docker-archive:<file>, oci-archive:<file> and oci-dir:<dir>. See Podman.
WebAssembly (Wasm)
safeguard wasm reads WebAssembly core modules and components from a .wasm file or a Wasm OCI artifact in a registry. Parsing is done in the CLI itself; no Wasm runtime and no Docker are needed.
safeguard wasm inspect <file.wasm | oci-ref> [--json] # kind, size, sha256, producers, imports/exports, embedded crates, custom sections, capabilities
safeguard wasm scan <file.wasm | oci-ref> [-o app.cdx.json] [--json] [--no-vulns] # CycloneDX 1.6 SBOM and advisories for embedded cratesAn OCI reference is oci://host/repo:tag, host/repo:tag or host/repo@sha256:<digest>. The manifest is pinned to its digest and each Wasm layer is checked against its digest. For a private registry pass --username <user> and the token on stdin with --password-stdin (or set SG_REGISTRY_USERNAME and SG_REGISTRY_PASSWORD). --key cosign.pub verifies cosign signatures; without it a signature is reported as present, not verified. --plain-http is for local test registries only. --max-bytes caps the file or layer size (default 512 MiB) and --timeout the registry access (default 300 seconds).
scan matches only dependencies embedded at build time (cargo-auditable) through the same vulnerability matcher as safeguard scan. Imports such as wasi:sockets or path_open are reported as informational or low capabilities, never as vulnerabilities. Every report ends with its limits. See WebAssembly (Wasm).
Apptainer and Singularity (SIF)
safeguard sif (also safeguard apptainer and safeguard singularity) inspects, verifies and scans Apptainer and Singularity images in the Singularity Image Format. Nothing in the image is run or mounted; the root filesystem is read in place.
safeguard sif inspect <image> [--json] # header, objects, architecture, definition file, labels
safeguard sif verify <image> [--json] [--key <file>]... [--keyring <file>]...
[--certificate <leaf.pem>] [--certificate-intermediates <pem>] [--certificate-roots <pem>] [--legacy-insecure]
safeguard sif scan <image> [--output <dir>] [--scanners <list>] [the verify key flags]<image> is a path to a .sif file, library://[host/]entity/collection/container[:tag] or oras://registry/repository[:tag|@sha256:<digest>]. For library://, --library-url names the library (Apptainer has no default library; a host in the reference is used when the flag is empty) and the token is read from the variable --library-token-env names (default SG_LIBRARY_TOKEN), never from a flag. For oras://, --registry-username and the variable --registry-password-env names (default SG_REGISTRY_PASSWORD). --arch (default amd64) and --pull-timeout (default 30m) apply to downloads; --plain-http is for a local test registry only.
verify reports each signature as verified (a cryptographic check passed), unverifiable (no key for it, or the keys given are not the signer's), or invalid, and each object as verified, unverifiable, invalid or unsigned. --key takes PGP public keys (armored or binary) and PEM public keys; --certificate keys are used only when the chain verifies with code signing usage, as apptainer verify requires. Exit status: 0 when every object is verified, 2 when anything is invalid, 3 otherwise.
scan writes the usual scan output plus sif-provenance.json (the file's sha256, where it came from, and the signature report). safeguard scan --image image.sif and safeguard scan image.sif scan a local SIF the same way. See Apptainer / Singularity (SIF).
Environment variables
The CLI has no API-key variable and no config-file path variable. The ones you are most likely to want:
| Variable | Effect |
|---|---|
SAFEGUARD_NO_BROWSER | The interactive terminal does not open a browser for /login (also the case when CI is set). For safeguard login, pass --no-browser |
SAFEGUARD_NO_UPDATE_CHECK=1 | Skip the background check for a new release |
SAFEGUARD_DISABLE_SELF_UPDATE=1 | Turn off binary updates entirely |
TOOLS_DIR | Directory to look in for the scanner tools |
LOG_DIR | Where to write safeguard.log (default ~/.sg/logs) |
The installer reads its own variables, listed on Installation.
Getting help
safeguard --help
safeguard scan --help
safeguard detect --help
safeguard validate --help