Join our Newsletter — 33% off our NHI Course
Architecture & Implementation

Build Stage

← Back to Glossary
By NHI Mgmt Group Updated November 3, 2026 Domain: Architecture & Implementation

A build stage is a named phase in a multi-stage container build that produces an intermediate image for a specific purpose, such as compiling code or preparing runtime files. Later stages can copy only the required artefacts from it, reducing image size and limiting what ends up in the final container.

What a build stage does

A build stage is an intermediate step in a multi-stage container build that performs one job well, such as compiling source code, installing dependencies, or assembling runtime files. Because later stages can copy only the needed artefacts forward, build stages help separate build-time tooling from the final image.

This separation matters because the contents of a build stage are not meant to be deployed as-is. Compilers, package managers, test tools, and temporary files can remain behind in the intermediate stage while the runtime stage stays smaller and easier to inspect.

Why build stages are used

Build stages exist to make container images more focused. A single Dockerfile can use one stage for dependency resolution, another for compilation, and a final stage for the runtime payload. That pattern is common when the build environment needs tools that should not ship to production.

The main practical benefit is reducing image bloat. Smaller final images usually mean faster pulls, less storage use, and a smaller surface for software that never needs to run in production. In many cases, the build stage also makes it easier to use a different base image for building than for running.

Build stages also make the build graph easier to reason about. You can name a stage, copy artefacts from it, and keep the final image explicit about what it contains. That clarity is valuable when multiple outputs are produced from the same source tree.

Security implications of build stages

Build stages are a major control point for limiting what ends up in an image. They help prevent build-only tools, caches, and transient files from being copied into the runtime layer. That is especially important when the build process touches package registries, signing tools, or secret material that should never be present in the shipped artefact. See Secrets in Container Images and Build Artefacts Guide for the risks created when sensitive data leaks into layers or intermediate outputs.

Build stages also support a tighter runtime posture by letting teams pair the build process with a minimal final image. A smaller runtime stage reduces the amount of code an attacker can abuse after compromise and makes unexpected files easier to spot during review. The pattern aligns with Hardened and Minimal Base Images Guide, which covers how minimal images change the defensive profile of the final container.

Because the intermediate stage is not the deployed artefact, it should be treated as build infrastructure, not production runtime. That distinction matters for provenance, scanning, and trust decisions: a secure final image can still be undermined if the build stage introduces compromised dependencies, unsafe scripts, or hidden artefacts.

How build stages fit into container supply-chain hygiene

Build stages are one piece of a broader container supply-chain discipline. They do not guarantee safety by themselves, but they help separate concerns so that dependency installation, compilation, and packaging can be audited independently. That separation makes it easier to inspect what was produced, what was copied forward, and what was intentionally excluded.

In practice, teams use build stages together with pinned inputs, repeatable builds, and artefact review. The goal is to make the final image derived from the build stage as deterministic and minimal as possible, while keeping the build process itself observable and controlled. For supply-chain provenance and build integrity context, SLSA is the most relevant external reference.

Build stages are therefore less about “making Dockerfiles longer” and more about enforcing a clean boundary between what is needed to build and what is needed to run. When that boundary is well designed, it improves both operational efficiency and security reviewability.

Risk and Threat Considerations

Build stages reduce exposure, but they also create a place where sensitive material, unsafe dependencies, or malicious build steps can exist before the final image is assembled. If that intermediate environment is compromised, the attacker may influence what gets copied into the runtime image or what is left behind in registries and caches.

Failure mechanism: The build stage pulls in untrusted components, processes secrets, or produces hidden artefacts that survive into later layers or artefact stores, allowing compromise to persist beyond the build itself.

Impact: The final container can ship with embedded secrets, unwanted tooling, tampered binaries, or a larger attack surface than intended, increasing the chance of exploitation and post-deployment discovery.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

SLSA, NIST SP 800-53 Rev 5, CIS Controls v8 and OWASP ASVS set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
SLSASupply-chain Levels for Software ArtifactsBuild stages shape artefact provenance and integrity in container supply chains
Recommendation — Use SLSA to harden build provenance and verify which artefacts are copied into the final image.
NIST SP 800-53 Rev 5CM-6 — Configuration SettingsBuild stages influence what software and files are present in the deployed container
SI-7 — Software, Firmware, and Information IntegrityBuild stages can introduce tampered or untrusted artefacts into container output
Recommendation — Apply CM-6 to keep the final image limited to approved runtime components. Use SI-7 to validate build outputs before promoting them into runtime images.
CIS Controls v8CIS-4 — Secure Configuration of Enterprise Assets and SoftwareContainer build stages are part of secure software configuration and image hardening
Recommendation — Use CIS-4 to standardise hardened build and runtime image configurations.
OWASP ASVSV15 — Secure Coding and ArchitectureMulti-stage builds are an architectural pattern that separates build-time and runtime concerns
Recommendation — Apply V15 to ensure build-stage separation supports secure application packaging.

Practitioner Guidance

Why practitioners should care: A build stage is only useful when it creates a real trust boundary between build-time activity and runtime delivery. If teams treat the stage as a convenience only, they can accidentally copy forward debug tools, private keys, or package caches that should never reach production.

What to watch for: Review what each stage installs, generates, and copies forward, especially when the build process touches secrets, private package feeds, or generated binaries. The final image should contain only the artefacts required to run, not the machinery that produced them.

Practitioner takeaway: Design build stages so the final runtime image is a deliberate subset of the build output, not a by-product of the entire build environment.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 3, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org