Summary
BentoML versions prior to 1.4.37 allow arbitrary command execution during container image builds through the docker.system_packages field in bentofile.yaml.
Because arbitrary strings from system_packages are interpolated directly into Dockerfile RUN commands without sanitization, a malicious or compromised configuration file can inject shell commands into the build process.
Affected context
This vulnerability appears in BentoML projects that:
- Use
bentofile.yamlto define container build configuration - Rely on the
docker.system_packagesfield to declare OS packages - Invoke
bentoml containerizeor otherwise triggerdocker buildusing generated Dockerfiles
The risk is elevated in workflows where bentofile.yaml is obtained from external sources, shared repositories, or automated pipelines where its contents are not reviewed or trusted by operators.
Exploit preconditions
- Attack surface: The BentoML build pipeline, specifically Docker image creation via
bentoml containerizeor equivalentdocker buildcommands. - Required access: Ability to create, modify, or influence
bentofile.yamlin the project being containerized (e.g., via repository write access, pull requests merged without scrutiny, or supply-chain compromise). - Trigger point: Execution of the container build process that reads
docker.system_packagesand interpolates its values into DockerfileRUNinstructions. - Why exploitation is possible: The
system_packagesfield is treated as data but is composed into shell command lines without quoting, escaping, or validation, enabling injected tokens to be interpreted as additional shell commands during the build.
Why this happens
The core issue is treating configuration data as executable shell content. The docker.system_packages field is conceptually a list of OS package identifiers, but during Dockerfile generation its entries are concatenated directly into RUN instructions.
Without proper escaping, quoting, or structural separation between data and command syntax, malicious values can break out of the intended package list and introduce arbitrary shell operators and commands. This aligns with CWE-94: Improper Control of Generation of Code ('Code Injection'), where untrusted input is incorporated into executable statements—in this case, shell code inside Docker build steps.
Potential impact
- Execution of arbitrary shell commands during container image build.
- Installation of backdoors or malicious binaries into generated images.
- Exfiltration of secrets available to the build environment (e.g., tokens, credentials, build-time environment variables).
- Compromise or lateral movement within CI/CD infrastructure that performs the build.
- Tampering with application behavior through modified runtime dependencies in the built container.
General mitigation guidance
Defenses generally focus on treating configuration fields as data only and hardening the build pipeline:
- Use structured representations for package lists (e.g., arrays) and compose them into commands using robust escaping or parameterization patterns.
- Avoid direct string interpolation of untrusted configuration into shell commands; instead, use APIs or templating approaches that clearly separate commands from arguments.
- Apply input validation to configuration fields that ultimately influence build scripts, rejecting values that contain shell metacharacters or unexpected whitespace/control operators.
- Run build processes and CI/CD workers with least privilege, limiting access to sensitive credentials and host resources so that even if build-time commands are abused, impact is constrained.
- Prefer secure-by-default templates for Dockerfiles and build scripts that minimize custom shell concatenation and instead rely on well-defined build steps.
How teams detect issues like this
Organizations can identify and monitor for this class of issue through:
- Static analysis and linting: Rules that flag concatenation of configuration-derived strings into Dockerfile
RUNcommands or shell statements without escaping. - Configuration review: Code review checklists that explicitly require inspection of
bentofile.yamland similar build-time configuration for executable content or suspicious tokens (e.g.,;,&&,|, backticks). - Policy enforcement in CI: Pipelines that block builds when configuration fields include disallowed shell metacharacters or when Dockerfile templates deviate from vetted patterns.
- Image and build auditing: Scanning generated images for unexpected binaries, scripts, or outbound network behavior, and correlating with build logs to detect anomalous commands executed during
docker build.

