Skip to content

CLI Exit Codes and HTTP Status Mapping

agent-bom exposes the same domain through a CLI, an HTTP API, an MCP server, and a GitHub Action. CI gates and shell pipelines branch on agent-bom's exit code; HTTP clients branch on the API's status code. This page is the single contract that documents both, so a script writer never has to read the source to know what an exit code means.

CLI exit-code contract

The contract covers ok, findings, usage, auth, and server failures explicitly so automation can distinguish caller mistakes from control-plane outages.

Code Name Meaning Typical sources
0 success Command completed; no findings or all findings under the default or configured severity threshold. Any subcommand that finished cleanly; scan --exit-zero with vulnerability findings only.
1 scan verdict or operational failure Either (a) a scan gate matched — see "Why scan exits 1" below — or (b) a precondition failed: missing config, unreachable backend, missing required env var, dependency not present. Default high threshold or --fail-on-severity matched, an incomplete scan such as a missing or unreadable offline vulnerability database, agent-bom scan --demo (malicious package fails closed), --clickhouse-url missing, NVD unreachable, optional dependency not installed, agent-bom connect <provider> failing to verify or register.
2 usage, empty or incomplete check Invalid arguments, no input to act on, a report that contained no rows after filtering, an agent-bom skills scan with a file it could not scan, or an agent-bom check that could not complete (stale local DB, or no version given and the registry's latest version could not be resolved: version_source is absent and verdict: "incomplete"). Click UsageError (auto), agent-bom skills scan with no skill files, agent-bom fs on a directory with no packages, empty result rendering, agent-bom connect when the control plane rejects the payload (400/422), agent-bom check <package> without a version when the registry is unreachable.
3 policy gate failed An opt-in policy gate failed. Currently emitted by --require-fresh-db / AGENT_BOM_REQUIRE_FRESH_DB when the local vuln DB is stale. Otherwise reserved for future policy gates. agent-bom scan --require-fresh-db or agent-bom check --require-fresh-db against a stale local vuln DB.
4 (reserved) Reserved for "auth required" / "auth invalid" on commands that talk to an authenticated control plane. Not yet emitted.
5 (reserved) Reserved for "remote control-plane error" (5xx response from the API). Not yet emitted.
130 interrupted Process received SIGINT (Ctrl-C) — POSIX convention, kept for shell idiom compatibility. Long-running agent-bom proxy / agent-bom serve / agent-bom agents.
* subprocess passthrough When agent-bom shells out (e.g. native scanner binaries), the child's non-zero exit code is propagated. agent-bom shield, agent-bom run proxy invocations.

Why scan exits 1

agent-bom scan --demo --offline exits 1. That is the scanner working, not failing: the report is printed in full and the specific gate that matched is named on the last line of the output. A scan exits 1 when any of these hold.

Gate Opt-in? What it means
Default high severity gate / --fail-on-severity High is the default (the same as the GitHub Action); the flag selects another threshold A vulnerability met or exceeded the active threshold. Use --exit-zero only for an explicitly reporting-only vulnerability scan.
--fail-on-kev / --fail-if-ai-risk matched Yes — you set the flag A finding met the additional gate you asked to block on.
A policy rule failed Yes — --policy, or --model-policy-mode enforce / --require-model-signatures / --block-unsafe-model-formats (all default off) Your policy rejected the result.
A malicious or suspected malicious package was found No — fails closed A known-malicious advisory, or a typosquat or dependency-confusion match, which reads as suspected. Exiting 0 here would let the package install.
The scan did not complete No — fails closed A requested collector degraded or failed, or a cloud control errored or returned no data; scan_run.issues in the artifact says which. A partial artifact with zero findings must not read as clean. An errored control is missing evidence rather than a finding: it exits 1 through this gate, not the severity gate, so real failed controls are named first. A disabled cloud API recorded as not in use does not trip it. Nor does an image signature or referrer lookup that failed after the packages were scanned: it is an image_supply_chain_incomplete scan note and the signature stays unknown; --require-signature is the gate for that.
--push-url results were not delivered No — fails closed The control plane could not be reached or rejected the report after retries, so it does not hold this scan. The local report is unaffected. A report the server accepted and is still ingesting counts as delivered.
Outdated local vulnerability data that OSV did not back No — fails closed (opt out with --allow-stale-db / AGENT_BOM_ALLOW_STALE_DB) The local DB is past the age agent-bom db freshness warns about (or its freshness can't be trusted), and the scan was offline or live OSV did not answer. scan_run.issues carries a stale_local_data coverage issue.

A missing, empty, or unreadable local advisory database during scan --offline is an incomplete scan, so scan writes a partial artifact when an output was requested and exits 1. It is not a usage error (2) because the command and input were valid. The narrower check command retains its established precondition contract and exits 2 when its requested offline advisory lookup cannot start.

Malicious and suspected malicious packages

A flagged package always exits 1, and --exit-zero does not clear it. The wording follows the evidence:

malicious_basis Evidence check verdict and canonical_verdict, MCP and API status
known_malicious A malware advisory (MAL-, CWE-506 family), a tampered go.sum hash, or a confirmed pickle payload malicious
unspecified Flagged with no recorded reason malicious
name_similarity The name is close to a popular package; nothing reports it as malware suspected_malicious
dependency_confusion The name looks internal and has no public data; nothing reports it as malware suspected_malicious

is_malicious stays true for all four because every gate reads it, so read malicious_basis before calling a package malware. For a suspected package, confirm its name and publisher on the registry; the exit stays 1 for that name, as there is no allowlist. Reports, SARIF properties, CycloneDX (agent-bom:malicious-basis) and SPDX annotations carry the same basis, and CSV and Parquet add a malicious_basis column.

Nothing to scan

agent-bom fs <dir> on a directory with no packages, lockfiles or manifests exits 0 because a repository with no dependencies is normal in CI, but gets no grade: posture_grade is N/A, scan_run.outcome is partial, and a nothing_to_scan issue names the directory. To require packages in a gate, check that posture_grade is not N/A. A directory with IaC files that were evaluated is a complete scan, not this case. On the API, the same request keeps status: done and adds the message to warnings, with no grade.

An API scan whose every requested target failed, such as an unreachable image, ends with job status: failed, error set and scan_run.outcome: failed. If at least one target succeeded, the job is done and scan_run.outcome is partial.

A package the public registry answers 404 for is named in the scan summary and in a package_not_on_registry issue, and its row carries registry_not_found: true. If no scanned package exists, posture_grade is N/A. This does not change the exit code, because private packages are normal.

Skill and instruction scans

agent-bom skills scan . -f json -o skills.json writes its report and exits 1 if any file is classified as malicious. Benign and suspicious content return 0 under this default content gate. A zero exit does not prove the files are safe: inspect their verdicts and coverage in skills.json.

Use --ci or --fail-on-verdict suspicious to also block suspicious content. Use --audit-only for an explicitly reporting-only content scan. It preserves all findings, but cannot be combined with --ci, --fail-on-verdict, or their environment-variable equivalents. Explicit policy and review-verdict gates still apply in audit-only mode.

Outdated local data fails closed

When the local vulnerability DB is past the age agent-bom db freshness warns about, or its freshness can't be trusted (unreadable metadata, or a schema newer than this agent-bom), online runs also query OSV live. If the run is offline or OSV did not answer, the result rests on old data only:

Command Nothing at or above the gate Findings at or above the gate
check exits 2 (incomplete), verdict: "incomplete" exits 1, unchanged
scan exits 1 (incomplete scan, stale_local_data issue in scan_run) exits 1, unchanged
MCP check / POST /v1/scan/check status: "incomplete" status: "vulnerable", unchanged
MCP scan / API scan jobs scan_run outcome not complete unchanged

--exit-zero does not turn this into a pass. Every surface reports completeness: {status, reason} and vuln_data_freshness. For air-gapped operation where old local data is accepted, pass --allow-stale-db or set AGENT_BOM_ALLOW_STALE_DB=1: the result then exits as it would on fresh data, but completeness still says incomplete. The same opt-out makes the range-receipt warning for local rows the upgraded schema cannot verify (unverified_range) informational — it stays in scan_run.issues with affects_coverage: false and no longer turns the outcome partial. Without the flag that warning keeps the run partial (exit 1) whenever live OSV did not decide every such row; the undecided rows are reported as possibly_affected candidates, never as findings. --exit-zero covers vulnerability verdicts only and does not clear a partial outcome. --require-fresh-db / AGENT_BOM_REQUIRE_FRESH_DB is the stricter opt-in: it exits 3 on a DB older than AGENT_BOM_DB_STALE_DAYS (default 14) before any lookup, for check and scan alike, and takes precedence over --allow-stale-db.

scan defaults to a high vulnerability gate, the same default as the GitHub Action, so a report containing high or critical findings exits non-zero even when no threshold flag was passed. The malicious-package and incomplete-evidence gates also fail closed. An advisory matched only to a registry-selected range leaves applicability unresolved and makes the scan partial (exit 1); it does not increase confirmed vulnerability counts. A failed Docker MCP image expansion also produces a partial report, retaining results from the other servers. Use --fail-on-severity to choose a stricter threshold, or --exit-zero for an explicitly reporting-only vulnerability scan. --exit-zero never suppresses a malicious-package, policy, or incomplete-evidence failure. Add --warn-on when the reporting-only path should still print a named warning tier. It changes only the exit status: under -q the verdict still reads FAIL (exit forced to 0 by --exit-zero) when the default high gate matched.

Documentation, example and test paths are non-gating by default

Secret, native source-analysis and SARIF/Semgrep findings in illustrative paths are kept and labelled, but lowered to low, so the default high gate does not trip on sample code. A path counts as illustrative when a directory in it is docs/, doc/, documentation/, site-docs/, examples/, example/, samples/, sample/, test/, tests/, __tests__/, testing/, testdata/, fixtures/, __fixtures__/, __mocks__/, spec/ or specs/, or when the file is a Markdown/reStructuredText/AsciiDoc document, a README*, CHANGELOG* or CONTRIBUTING* file, or a test file (test_*.py, *_test.go, *.test.*, *.spec.*). Each such finding carries path_context (documentation, example or test) and a downgrade_reason. A credential a provider confirmed live (validation_status: valid) keeps its severity wherever it sits. To gate on these findings too, pass --fail-on-severity low.

Unknown severity fails closed

A finding whose severity is unknown (or none) trips any active severity gate, including the default high gate, because an unscored vulnerability must not silently pass CI. To keep that rare, a distro fix advisory that has no severity of its own (Debian DLA-/DSA-, Ubuntu USN-, AlmaLinux ALSA-, Red Hat RHSA-, and similar) takes the highest severity of the upstream CVEs it fixes. The scores come from records the scan already holds, then the local vulnerability database, then api.osv.dev for a scan that is not --offline (how and within what limits). The finding's severity_source names the CVE that supplied the score (upstream_cve:CVE-…), and severity_linked_cve repeats it on its own. EPSS and KEV attach through the same upstream CVEs. The advisory ID stays in vulnerability_id and advisory_ids, never in cve_ids.

An advisory stays unknown, and keeps failing closed, when none of its upstream CVEs has a usable score, and severity_note says why. Run agent-bom db update to refresh the local database, or review the finding and accept it with an ignore rule.

The unreserved codes (0, 1, 2, 130) are stable today. Codes 3, 4, 5 are reserved so future product growth has a clean place to land without re-numbering existing codes — operators may rely on if [ "$rc" -eq 0 ] and on the rc != 0 family without further branching today.

API status-code contract

Status Meaning Where it's raised
200 Success. All successful reads and writes.
201 Created. POST /v1/scan, POST /v1/auth/keys, SCIM POST /Users//Groups.
204 Deleted. DELETEs that succeed without a body.
400 Bad request — payload validation passed Pydantic but failed business-rule validation. Tenant-quota update with negative caps, invalid filter combinations.
401 Unauthenticated — no valid API key, OIDC bearer, SAML session, or trusted-proxy attestation. Middleware before route resolution.
403 Authenticated but not authorized — RBAC scope rule rejected the call. Cross-tenant access attempt, viewer role attempting admin operation.
404 Resource not found. Scan job, agent, registry server, key, or graph node not present in tenant.
409 Conflict — idempotency clash, duplicate key creation, concurrent state mutation. API key rotation, scan-job lifecycle conflicts.
422 Pydantic validation failure — payload shape rejected. FastAPI request-body validation.
429 Rate limited — per-tenant quota or global rate limit hit. Middleware PostgresRateLimitStore.
500 Server error — unexpected exception inside route logic. Bugs, downstream timeouts that escape retry budgets.
502 Upstream bad-gateway — proxied call (e.g. external scanner) returned an unparseable response. External scanner adapters.
503 Backend unavailable — Postgres, ClickHouse, or another required dependency is down. Health probes, dependency-aware routes.

All errors return {"detail": "<message>"} per FastAPI default. The UI client at ui/lib/api.ts parses detail, message, and error so that any of those keys surface to operators with a useful string.

How CLI codes correspond to API statuses

This is the explicit mapping that the CLI applies when it talks to the API and needs to translate an HTTP outcome into a process exit code. It's not a reflexive 1:1 mapping — several HTTP codes collapse into a single CLI code because shells care about families, not individual semantics.

CLI exit code HTTP status family Why
0 2xx The command did what it asked.
2 400 422 Caller sent something invalid — usage error, fix the input.
4 (reserved) 401 403 Caller is not (or not yet) authorized — fix credentials, not the input.
1 404 409 Operational state issue — resource missing, conflict — retryable after correcting state.
1 429 Throttled — retry with backoff. Today flattens to 1; future revisions may use a dedicated code.
5 (reserved) 5xx Control-plane fault — agent-bom is not at fault, retry or escalate.
130 n/a Operator pressed Ctrl-C; never originates from an HTTP response.

Because 4 and 5 are still reserved, the families that would map to them (401/403 and 5xx) flatten to 1 today rather than being emitted early. A command that talks to the control plane is therefore always safe to gate on rc != 0: agent-bom connect <provider> exits 2 when the control plane rejects the payload and 1 for every other failure — a failed credential verification, a rejected registration, an unreachable control plane, or a missing provider SDK extra. It never exits 0 without a verified connection, so agent-bom connect aws && <next step> cannot promote a broken connection. When the control plane returns an actionable detail, the CLI prints that message verbatim instead of a "see server logs" dead end.

Until reserved codes (3/4/5) are emitted, the safe shell idiom is:

agent-bom agents -p ./project --format sarif > out.sarif
rc=$?
case "$rc" in
  0)   echo "ok" ;;
  2)   echo "usage / empty"; exit 0 ;;     # treat empty as non-failure in some pipelines
  130) echo "interrupted"; exit 130 ;;     # propagate Ctrl-C semantics
  *)   echo "failed (rc=$rc)"; exit "$rc" ;;
esac

GitHub Action action.yml outputs

With severity-threshold: '' the Action step is report-only: exit-code still reports what the scanner returned, but severity findings and a partial scan do not fail the step. A malicious package, a failed scan and an explicit policy or fail-on-kev gate still do. The CLI's own default is unchanged.

The composite action surfaces the CLI exit code, parsed scan status, artifact paths, and AI-specific posture counts so downstream workflow steps can gate without re-parsing logs.

Output Type Source Notes
sarif-file string computed Path to the SARIF report when format: sarif was selected.
exit-code string propagated CLI exit code Same value documented in CLI exit-code contract.
scan-status string parsed from exit code + findings clean, violations, partial (report-only step with incomplete coverage), usage_error (exit 2), stale_data (exit 3), or error.
vulnerability-count string parsed from SARIF or skills JSON Number of vulnerability findings, or skill findings for scan-type: skills.
badge-file string computed Path to generated shields.io badge JSON when badge is set.
sbom-file string computed Path to the SBOM / AI-BOM artifact when sbom-artifact is cyclonedx or spdx.
graph-export-path string computed Path to generated mermaid, svg, graph, or graph-html artifact.
exposure-paths-count string read from the report JSON exposure_paths.path_count, or the SARIF run property exposure_path_count.
blast-radius-critical-count string read from the report Critical, unsuppressed blast_radius rows in JSON; SARIF results with security-severity >= 9.0 (possibly-affected rows excluded).
posture-grade string read from the report The scanner's own posture_grade (JSON root or SARIF run property): A-F, N/A when nothing was gradable, unknown when the artifact carries no grade. Never recomputed from counts.

Stability guarantees

  • 0, 1, 2, 130, and the subprocess passthrough are stable and will not be re-numbered within a major version.
  • 3, 4, 5 are reserved and will be assigned only to the meanings declared above.
  • The HTTP status mapping is a binding contract for shell pipelines; future status codes added to the API will fold into the same families described above unless a new CLI code is introduced (in which case it will be drawn from the reserved set, not allocated above 5).