To generate an SBOM, point an open-source generator at your source tree or container image and ask for a standard format: syft <image> -o cyclonedx-json=sbom.cdx.json, trivy image --format cyclonedx --output sbom.cdx.json <image>, or cdxgen -r -o bom.json .. Generate it in CI on every release, attach or attest it alongside the artifact, and scan it with Grype or Trivy so the SBOM becomes a vulnerability-response tool rather than a compliance PDF.
This tutorial shows the exact commands for Syft, Trivy and cdxgen, when to pick each, how to wire them into GitHub Actions, how to sign SBOMs as attestations, and where the EU Cyber Resilience Act now fits in.
SBOM Basics: What You Are Actually Producing
A software bill of materials is a machine-readable inventory of the components in a piece of software: package names, versions, package URLs (purls), hashes, licenses and, ideally, the dependency relationships between them. Its value comes from being queryable. When the next widely exploited library vulnerability lands, the question "which of our releases ship the affected version?" should be a search across stored SBOMs, not a week of grepping repositories.
CycloneDX vs SPDX
There are two formats worth producing. Both are open standards and every tool in this guide can emit both.
| CycloneDX | SPDX | |
|---|---|---|
| Steward | OWASP / Ecma TC54 | Linux Foundation |
| Current version | 1.7, released October 2025 and adopted as ECMA-424 2nd edition | 3.0 (3.0.1 published December 2024) per spdx.dev; 2.x still widely emitted |
| International standard | ECMA-424 | ISO/IEC 5962:2021 (covers SPDX 2.2.1) |
| Origin and strength | Security use cases: vulnerabilities, VEX, services, crypto assets | License compliance, provenance, legal review |
| Typical file names | bom.json, *.cdx.json |
*.spdx.json, *.spdx |
In practice: use CycloneDX JSON as your default for security tooling, and produce SPDX JSON as well if a customer, a legal team or a platform (for example Docker's BuildKit attestations, which are SPDX) expects it. The CycloneDX 1.7 announcement and the SPDX specifications page are the authoritative references.
Source SBOM vs image SBOM
Where you point the generator changes what you get:
- Source/manifest SBOM (scanning a repo checkout): reads lockfiles and manifests. Precise for application dependencies, blind to the OS packages in your runtime image.
- Image SBOM (scanning a built container): sees OS packages (apk, dpkg, rpm) plus language packages actually installed in the image. Closer to what you ship, but it can miss build-time context and dev dependencies.
Most teams end up generating both: a source SBOM during the build and an image SBOM of the final artifact.
Tool Comparison: Syft vs Trivy vs cdxgen
| Syft | Trivy | cdxgen | |
|---|---|---|---|
| Maintainer | Anchore | Aqua Security | CycloneDX / OWASP community |
| Primary job | SBOM generation | Security scanner (vulns, misconfig, secrets) that also emits SBOMs | SBOM generation, deep language support |
| Output formats | CycloneDX JSON/XML, SPDX JSON/tag-value, Syft JSON, more | CycloneDX JSON, SPDX, SPDX JSON | CycloneDX (1.6, 1.7, 2.0), SPDX 3.0.1 JSON-LD |
| Best at | Container images, fast and broad ecosystem coverage | One binary for SBOM plus scanning | Polyglot source repos, reachability/evidence data |
| Scanning partner | Grype | Built in (trivy sbom) |
Any CycloneDX consumer |
| Runtime | Single Go binary | Single Go binary | Node.js 24+ or container/standalone binary |
All three are free and open source. If you only want one tool, Trivy gives you generation and scanning in one binary. If SBOM quality on images is the priority, Syft plus Grype is the most common pairing. If you have a monorepo with Java, Python, JavaScript and Go side by side, cdxgen tends to produce the richest source SBOM.
Generating SBOMs with Syft
Install
From the Syft README:
curl -sSfL https://get.anchore.io/syft | sudo sh -s -- -b /usr/local/bin
syft version
Homebrew, Docker, Scoop and other installers are listed in the Syft installation docs. Piping a script into a shell is convenient on a laptop; in CI, prefer a pinned release binary with checksum verification.
Commands
# Container image from a registry (no Docker daemon needed)
syft registry:ghcr.io/acme/api:1.4.2 -o cyclonedx-json=sbom.cdx.json
# Local source directory
syft dir:. -o cyclonedx-json=sbom.cdx.json
# Both formats in one pass
syft ghcr.io/acme/api:1.4.2 \
-o spdx-json=sbom.spdx.json \
-o cyclonedx-json=sbom.cdx.json
# Include packages from every image layer, not just the final filesystem
syft ghcr.io/acme/api:1.4.2 --scope all-layers -o cyclonedx-json=sbom-all-layers.cdx.json
The -o FORMAT=PATH form writes to a file, and you can repeat -o to produce several formats from a single scan. Source prefixes per the Syft CLI reference are dir:, file:, docker: (local daemon), registry: (pull directly) and oci-archive:. Without a prefix Syft guesses, which is usually fine on a laptop but worth making explicit in CI. Format names include cyclonedx-json, cyclonedx-xml, spdx-json, spdx-tag-value, syft-json and purls.
The default --scope is squashed, meaning Syft catalogs what is visible in the final image filesystem. all-layers also reports packages that were installed and later deleted in a lower layer; that is noisier but occasionally useful when auditing a base image.
Generating SBOMs with Trivy
A note on the March 2026 Trivy compromise
Before using Trivy in CI, know what happened in March 2026. According to Aqua Security's advisory, on March 19, 2026 an attacker using stolen credentials published a malicious Trivy v0.69.4 binary and force-pushed most aquasecurity/trivy-action version tags and the setup-trivy tags to malicious commits. Docker Hub images tagged 0.69.5 and 0.69.6 were also flagged. The advisory says anything that ran the affected builds or tags during March 19–20 should be treated as compromised, with all secrets reachable from those runners rotated.
The lesson applies to every tool in this article: pin GitHub Actions to a full commit SHA, not a version tag, and pin binaries by version and checksum. Aqua's advisory explicitly notes that tags can be moved to point at malicious commits.
Commands
From the Trivy SBOM documentation:
# CycloneDX SBOM of a container image
trivy image --format cyclonedx --output sbom.cdx.json ghcr.io/acme/api:1.4.2
# SPDX JSON SBOM of a container image
trivy image --format spdx-json --output sbom.spdx.json ghcr.io/acme/api:1.4.2
# CycloneDX SBOM of a source directory
trivy fs --format cyclonedx --output sbom.cdx.json .
# CycloneDX SBOM that also embeds vulnerability findings
trivy image --scanners vuln --format cyclonedx --output sbom-with-vulns.cdx.json ghcr.io/acme/api:1.4.2
Supported SBOM --format values are cyclonedx, spdx (tag-value) and spdx-json; CycloneDX XML is not supported. One gotcha: --format cyclonedx disables vulnerability scanning by default and Trivy prints a notice saying so. That is usually what you want, since an SBOM should be an inventory and vulnerability data goes stale within days, but add --scanners vuln if a downstream consumer expects findings embedded in the document.
Generating SBOMs with cdxgen
Install
cdxgen changed its package name in v13. Per the cdxgen README, the current npm package is @cdxgen/cdxgen; the old @cyclonedx/cdxgen name installs v12 or earlier. The npm package needs Node.js 24 or later.
# Install line from the cdxgen README (skips install scripts, 2-day release cooldown)
npm install -g @cdxgen/cdxgen --ignore-scripts --min-release-age=2
# Or run the container image with your project mounted at /app
docker run --rm -v "$PWD":/app ghcr.io/cdxgen/cdxgen:master -r /app -o /app/bom.json
Standalone binaries are also published on the project's GitHub releases, which is the better option for CI.
Commands
# Auto-detect project type in the current directory
cdxgen -o bom.json .
# Force a project type
cdxgen -t java -o bom.json .
# Recursive: one BOM covering every language found in a monorepo
cdxgen -r -o bom.json .
# Pin the CycloneDX spec version (default is 1.7)
cdxgen -r -o bom.json --spec-version 1.6 .
# SPDX 3.0.1 JSON-LD instead of CycloneDX
cdxgen -r --format spdx -o bom.spdx.json .
Pinning --spec-version 1.6 is useful when a downstream platform has not caught up with CycloneDX 1.7 yet. cdxgen also has a server mode (cdxgen --server, default port 9090, with a /health endpoint) if you want to generate SBOMs as a service for many repositories.
Because cdxgen often resolves dependencies by invoking the language's own build tool (Maven, Gradle, pip and so on), run it after the project's dependencies are installed, in an environment that matches your build.
Scanning an SBOM for Vulnerabilities
An SBOM you never query is shelfware. Both Grype and Trivy accept an SBOM as input, which means you can re-scan old releases against today's vulnerability data without rebuilding anything.
Grype
curl -sSfL https://get.anchore.io/grype | sudo sh -s -- -b /usr/local/bin
# Scan an SBOM file
grype sbom:./sbom.cdx.json
# Fail the build on high or critical findings (exit code 2)
grype sbom:./sbom.cdx.json --fail-on high
# SARIF output for GitHub code scanning
grype sbom:./sbom.cdx.json -o sarif > grype.sarif
Per the Grype CLI reference, --fail-on (-f) accepts negligible, low, medium, high or critical and sets the exit code to 2 when a finding meets that threshold. Output formats include table, json, cyclonedx, cyclonedx-json and sarif.
Trivy
trivy sbom ./sbom.cdx.json
trivy sbom --severity HIGH,CRITICAL --exit-code 1 ./sbom.cdx.json
Re-scan on a schedule
The high-value pattern is a nightly job that loops over the SBOMs of every release still in production and re-scans them. New CVEs are published daily; your SBOMs do not change. That loop is also the fastest way to answer the "are we affected?" question that the CRA's reporting obligations now put on a clock.
SBOMs in CI: A GitHub Actions Workflow
This workflow builds a container image, generates a CycloneDX SBOM with Syft via anchore/sbom-action, fails on critical vulnerabilities with Grype, and attaches a signed SBOM attestation with actions/attest.
name: build-and-sbom
on:
push:
tags: ['v*']
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # push to GHCR
id-token: write # sign attestations
attestations: write # store attestations
artifact-metadata: write # listed as required in the actions/attest README
steps:
# In production, pin every action below to a full commit SHA.
- uses: actions/checkout@v6
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
- name: Build and push
id: build
run: |
IMAGE=ghcr.io/${{ github.repository }}:${{ github.ref_name }}
docker build -t "$IMAGE" .
docker push "$IMAGE"
DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$IMAGE" | cut -d@ -f2)
echo "image=ghcr.io/${{ github.repository }}" >> "$GITHUB_OUTPUT"
echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"
- name: Generate SBOM
uses: anchore/sbom-action@v0
with:
image: ${{ steps.build.outputs.image }}@${{ steps.build.outputs.digest }}
format: cyclonedx-json
output-file: sbom.cdx.json
upload-artifact: true
- name: Scan SBOM with Grype
run: |
curl -sSfL https://get.anchore.io/grype | sh -s -- -b "$RUNNER_TEMP/bin"
"$RUNNER_TEMP/bin/grype" sbom:./sbom.cdx.json --fail-on critical
- name: Attest SBOM
uses: actions/attest@v4
with:
subject-name: ${{ steps.build.outputs.image }}
subject-digest: ${{ steps.build.outputs.digest }}
sbom-path: sbom.cdx.json
push-to-registry: true
Notes on the design:
- Scan the SBOM, not the image again. Generating once and scanning the SBOM guarantees the vulnerability report and the stored inventory describe exactly the same components.
actions/attest-sbomis deprecated. Its README says v4 is a thin wrapper aroundactions/attestand recommends migrating. The SBOM file must be SPDX or CycloneDX JSON and cannot exceed 16 MB.- Attest against the digest, not the tag. Tags move (as the Trivy incident showed); digests do not.
Verifying an SBOM attestation
Consumers verify with the GitHub CLI. GitHub's documentation notes you must pass --predicate-type because SBOMs are not the default SLSA provenance predicate. Its SPDX example:
gh attestation verify oci://ghcr.io/acme/api:1.4.2 \
-R acme/api \
--predicate-type https://spdx.dev/Document/v2.3
For a CycloneDX attestation, run the command with --format json first to see the predicate type recorded in the attestation, then enforce that value.
Docker BuildKit alternative
If you build with Buildx, BuildKit can generate and attach an SBOM itself. Per Docker's docs, it uses a Syft-based scanner plugin and stores the result as an SPDX in-toto attestation on the image:
docker buildx build --tag ghcr.io/acme/api:1.4.2 --sbom=true --push .
docker buildx imagetools inspect ghcr.io/acme/api:1.4.2 \
--format "{{ json .SBOM.SPDX }}"
This is the lowest-effort option if SPDX is acceptable, but you lose control over the generator version and format.
Where the EU Cyber Resilience Act Fits
The Cyber Resilience Act (Regulation (EU) 2024/2847) is the reason many teams are suddenly being asked for SBOMs. The European Commission's CRA summary gives the timeline:
| Date | Milestone |
|---|---|
| 10 December 2024 | CRA entered into force |
| 11 June 2026 | Provisions on notification of conformity assessment bodies apply |
| 11 September 2026 | Article 14 reporting obligations apply: actively exploited vulnerabilities and severe incidents must be reported |
| 11 December 2027 | Regulation fully applicable, including the essential cybersecurity requirements in Annex I |
The SBOM requirement itself sits in Annex I, Part II, point 1: manufacturers must identify and document components, "including by drawing up a software bill of materials in a commonly used and machine-readable format covering at the very least the top-level dependencies," as quoted by Socket's CRA glossary among others. That becomes mandatory with full application in December 2027, and the regulation does not mandate CycloneDX or SPDX specifically.
So why act now? Because the reporting obligations have applied since 11 September 2026, including to products already on the market. Several compliance analyses, such as TechTarget's overview for CISOs, describe an early warning within 24 hours of becoming aware of an actively exploited vulnerability. You cannot meet a 24-hour clock if finding out whether you ship the vulnerable component takes days. Stored, scannable SBOMs per release are the practical prerequisite. This is general information, not legal advice; confirm your obligations against the regulation text.
For a wider view of the commercial platforms that store and manage SBOMs at scale, see our roundup of SBOM management tools, and for image scanning in production, container security platforms. Our DevSecOps platforms overview covers where SBOM generation fits in a broader pipeline. If you need to eyeball a large SBOM, the JSON formatter in our developer tools helps.
Frequently Asked Questions
What is the best free SBOM tool?
There is no single winner. Syft is the most common choice for container images and pairs with Grype for scanning. Trivy is convenient when you want SBOM generation and vulnerability scanning in one binary. cdxgen usually produces the most detailed SBOMs for polyglot source repositories. All three are open source and can output both CycloneDX and SPDX.
Should I use CycloneDX or SPDX?
Use CycloneDX JSON as the default for security workflows, since vulnerability scanners and VEX tooling are built around it. Produce SPDX as well when customers, legal teams or platforms such as Docker BuildKit expect it. Generating both from one scan costs almost nothing with Syft (-o spdx-json=... -o cyclonedx-json=...).
Does the EU Cyber Resilience Act require an SBOM?
Yes, but the SBOM requirement in Annex I applies with the regulation's full application on 11 December 2027, and it requires at least top-level dependencies in a commonly used, machine-readable format. The reporting obligations under Article 14 already apply since 11 September 2026, and SBOMs are what make those deadlines achievable in practice.
How often should I generate an SBOM?
Generate one for every build artifact you release, in CI, and store it next to the artifact (as a release asset or registry attestation). Then re-scan stored SBOMs on a schedule, because new vulnerabilities are disclosed constantly while your released components stay the same.
Can I generate an SBOM from a container image without Docker installed?
Yes. Syft's registry: source pulls image layers directly from a registry without a container runtime, for example syft registry:ghcr.io/acme/api:1.4.2 -o cyclonedx-json. Trivy can also scan remote images directly.
Why does my Trivy CycloneDX SBOM contain no vulnerabilities?
Because --format cyclonedx disables vulnerability scanning by default, which Trivy announces in a notice. Add --scanners vuln if you want findings embedded, or keep the SBOM as a clean inventory and scan it separately with trivy sbom or Grype.
Conclusion
Producing an SBOM is a one-line command; producing a useful SBOM program is a few more steps. Pick a generator that matches your stack (Syft for images, cdxgen for polyglot source, Trivy if you want one tool), emit CycloneDX JSON on every release, scan the SBOM rather than re-scanning the artifact, attest it against the image digest, and re-scan stored SBOMs nightly. Pin every action and binary you use to do this, because the March 2026 Trivy incident showed that security tooling is itself a supply-chain target. With the CRA's reporting clock already running, the teams that can answer "do we ship it?" in minutes are the ones that started storing SBOMs before they needed them.