Summary
The llm CLI tool up to version 0.27.1 allows users to pass arbitrary Python code via the --functions argument, which is executed directly with exec() without any safety checks.
An attacker can craft a malicious command line and, through social engineering, convince a user to run it, resulting in arbitrary code execution with the user's privileges.
Affected context
This vulnerability occurs when the llm CLI is invoked with the --functions parameter, which is designed to accept user-supplied Python function definitions.
In affected versions, whatever is passed to --functions is executed as Python code in the context of the running process, inheriting the privileges and environment of the invoking user.
The risk is most pronounced in environments where llm commands are shared in documentation, scripts, chat messages, or automation, and users copy-paste or execute them without inspection.
Exploit preconditions
- Attack surface: Command-line interface of the llm tool (
llmexecutable). - Required access: Ability to influence or control how a victim runs the
llmcommand (e.g., via shared scripts, documentation snippets, or messages). - Trigger point: Execution of
llmwith a malicious payload passed to the--functionsargument. - Why exploitation is possible: The input supplied to
--functionsis treated as trusted Python source and executed viaexec()without sanitization, sandboxing, or any restriction on what the code can do.
Why this happens
The underlying issue is the direct execution of untrusted input as code, a classic example of CWE-94: Improper Control of Generation of Code ('Code Injection').
The llm tool exposes a feature that accepts arbitrary Python code from a command-line flag and uses Python's exec() to evaluate it in the main interpreter context.
There is no separation between trusted application logic and untrusted user input, so any code a user or attacker provides is executed with full access to the process, filesystem, and network.
Architecturally, this couples extensibility (custom functions) to raw code evaluation instead of using a constrained, declarative, or sandboxed mechanism.
Potential impact
- Execution of arbitrary commands and programs with the victim user's privileges.
- Reading, modifying, or deleting files accessible to the victim account.
- Installation of malware or backdoors on the victim system.
- Exfiltration of sensitive data such as API keys, SSH keys, or configuration files.
- Use of the compromised system as a pivot point for further attacks within the network.
General mitigation guidance
Effective mitigation focuses on removing or strictly containing the execution of untrusted code:
- Replace direct
exec()usage with safer extensibility mechanisms, such as: - Predefined, whitelisted functions that users can reference by name.
- Declarative configuration or function descriptors that are interpreted, not executed as raw code.
- If dynamic behavior is required, consider:
- Running user-defined logic in a separate confined process or container with minimal privileges and strict resource limitations.
- Applying sandboxing techniques (e.g., OS-level isolation, seccomp, or constrained interpreters) to reduce the blast radius.
- Treat all command-line parameters as untrusted input and avoid patterns that interpret them as executable code.
- Encourage operational practices that discourage copy-pasting unvetted commands from untrusted sources, especially those including
--functionsor similar powerful flags.
How teams detect issues like this
Detection typically involves both code-level and operational controls:
- Static analysis and code review:
- Flag direct use of
exec()andeval()on data derived from command-line arguments or other untrusted sources. - Review CLI argument handlers for any logic that transforms user input into executable code.
- Policy and automated checks:
- Enforce secure coding policies that prohibit arbitrary code execution primitives in user-facing features.
- Integrate linters or security-focused static analysis tools into CI pipelines to detect banned APIs or unsafe patterns.
- Runtime monitoring:
- Monitor for suspicious invocation patterns of the llm binary that include complex or unexpected content in
--functions. - Use endpoint protection to detect anomalous behavior resulting from CLI tools spawning shells, modifying sensitive files, or making unexpected network connections.

