Summary
BentoML's cloud deployment pipeline previously interpolated the system_packages value directly into a shell command using an f-string without proper quoting or sanitization.
When an attacker can influence system_packages, they may inject arbitrary shell commands into the generated setup.sh script, leading to remote code execution on the CI/CD build infrastructure during cloud deployment.
Affected context
This vulnerability arises in BentoML environments using the cloud deployment path, where deployment configuration values (such as system_packages) are used to generate shell scripts executed in the BentoCloud build environment.
The issue is specifically tied to a code path in src/bentoml/_internal/cloud/deployment.py that constructs a shell command via an f-string and embeds system_packages without quoting or escaping, making any untrusted or user-controlled content in that field risky when deployments are triggered.
Exploit preconditions
- Attack surface: BentoML cloud deployment pipeline (BentoCloud build infrastructure).
- Required access: Ability to supply or modify deployment configuration that controls
system_packages(e.g., via project configuration, deployment specification, or CI variables). - Trigger point: Initiation of a cloud deployment that causes BentoML to generate and upload
setup.sh, which is then executed by the cloud build system. - Why exploitation is possible: The
system_packagesvalue is interpolated directly into a shell command using an f-string without quoting or escaping, allowing shell metacharacters to break out of the intended context and execute attacker-controlled commands.
Why this happens
The core issue is a classic OS command injection, mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command.
Instead of treating system_packages as data and passing it to the shell via a safe API, the code constructs a shell command string with direct interpolation, leaving any embedded spaces, semicolons, backticks, or other metacharacters unfiltered.
This pattern blurs the boundary between code and data in shell scripts, so user-influenced values can alter the control flow of the command line, enabling arbitrary command execution when the resulting setup.sh script runs in the CI/CD environment.
Potential impact
- Compromise of the CI/CD build environment running BentoCloud deployments.
- Execution of arbitrary commands with the privileges of the build agent or container.
- Theft or modification of sensitive build artifacts, environment variables, or credentials accessible in the pipeline.
- Lateral movement from the CI/CD tier into connected services or infrastructure.
- Tampering with deployed AI models or application components, leading to supply-chain risk.
General mitigation guidance
Effective mitigation focuses on separating data from shell execution and reducing trust in deployment configuration values:
- Prefer high-level process execution APIs (e.g., passing arguments as arrays) rather than constructing shell command strings.
- If shell usage is unavoidable, quote and escape all interpolated variables and restrict allowed characters for fields like
system_packagesthrough validation. - Treat deployment configuration as untrusted input by default, even if nominally controlled by internal users, and validate against an allowlist of known-safe package names or patterns.
- Run CI/CD build steps and deployment preparation in hardened, least-privilege environments with minimized access to secrets and infrastructure.
- Introduce secure-by-default helper functions for script generation so developers avoid direct f-string shell construction.
How teams detect issues like this
Security teams can look for this pattern using a combination of static analysis and code review:
- Configure static analysis rules to flag string interpolation or concatenation used to build shell commands, especially where user or configuration input (like
system_packages) is involved. - Add code review checklists that highlight any usage of
os.system,subprocesswithshell=True, or generated shell scripts, and require justification and safe handling patterns. - Implement policy-based checks in CI that scan for unsafe shell construction patterns (e.g., grep or semgrep rules around deployment-related modules and script generation).
- Periodically review CI/CD logs for anomalous commands or unexpected behavior during cloud builds, which may indicate attempted command injection.

