Summary
OpenClaw contained a command injection vulnerability in its Docker sandbox execution mechanism caused by unsafe handling of the PATH environment variable when building shell commands.
An authenticated user who could control environment variables was able to influence which binaries were executed inside the container, potentially leading to arbitrary command execution in the sandboxed environment.
Affected context
This vulnerability affects OpenClaw deployments that:
- Use the Docker-based sandbox execution mechanism for running commands or tools
- Allow authenticated users or integrated components to influence environment variables, particularly PATH
- Build shell commands that are executed inside a container, relying on PATH-based resolution of executables
The issue manifests when untrusted or semi-trusted input can modify PATH or related environment variables used by shell command construction in the sandbox.
Exploit preconditions
- Attack surface: OpenClaw Docker sandbox execution mechanism (within container runtime)
- Required access: Authenticated access with the ability to control or influence environment variables, especially PATH
- Trigger point: Execution of shell commands constructed by OpenClaw that rely on PATH for binary resolution
- Why exploitation is possible: The PATH environment variable is used directly when constructing or executing shell commands, allowing an attacker-controlled PATH to redirect execution to attacker-supplied binaries or scripts instead of intended system utilities.
Why this happens
The core issue is an instance of CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
OpenClaw's Docker sandbox accepted environment values such as PATH from an authenticated context and incorporated them into shell-based command execution logic without enforcing strict validation, canonicalization, or safe command construction patterns.
By allowing untrusted input to influence PATH and relying on shell resolution, the application effectively delegated trust in which executable is run to user-controlled data.
This pattern breaks the security boundary between configuration and execution, enabling an attacker to alter command behavior or inject alternative binaries inside the container.
Potential impact
- Execution of attacker-controlled binaries or scripts inside the Docker container
- Bypass of intended command restrictions by shadowing legitimate utilities with malicious ones
- Unauthorized access to data or secrets accessible within the containerized environment
- Escalation of privileges within the container if higher-privileged helper tools are invoked
- Use of the compromised container as a pivot point for further attacks in the surrounding infrastructure, depending on network and permission configuration
General mitigation guidance
Effective mitigation typically focuses on removing the dependency on user-influenced environment variables for security decisions and shell command resolution:
- Construct commands using fixed, absolute paths to trusted binaries rather than relying on PATH lookup.
- Sanitize and constrain environment variables passed into the sandbox; do not propagate user-controlled PATH values into security-sensitive execution contexts.
- Prefer high-level APIs (e.g., direct system calls or language-native libraries) over spawning shell commands wherever possible.
- When shell invocation is unavoidable, disable shell interpretation features (e.g., use execve-style calls or subprocess APIs with argument arrays and shell=False semantics).
- Apply least-privilege principles inside the container by limiting available tools, file system access, and outbound connectivity to reduce blast radius if command injection occurs.
- Separate trust domains: treat any environment configuration that can be influenced by end users as untrusted input, enforcing strict allowlists for environment variables in execution sandboxes.
How teams detect issues like this
Detection commonly involves a mix of code-level and behavioral approaches:
- Static analysis: Create rules or queries to flag:
- Shell command construction that depends on PATH or other dynamic environment variables
- Use of generic shell wrappers (e.g., /bin/sh -c, bash -c) combined with concatenated strings or user-influenced data
- Code paths where user-controlled settings or profile data flows into environment preparation for subprocesses
- Code review signals:
- Any use of PATH or other environment variables in security-sensitive operations
- Reliance on environment propagation from user sessions into sandboxed containers
- Lack of explicit whitelisting or fixed binary paths in command execution logic
- Runtime and policy enforcement:
- Container security policies that restrict writable locations in PATH and disallow execution from non-standard directories
- Monitoring of container processes for unexpected binaries being executed or binaries sourced from user-writable paths
- Automated SAST/IAST tools and CI hooks can surface these patterns early, especially when configured with organization-specific rules for command execution and environment handling.

