/

CVE-2026-31236

Severity:

CRITICAL RISK

(9.8)

Code Injection in llm CLI --functions Argument

CVE-2026-31236

Awaiting Analysis

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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 (llm executable).
  • Required access: Ability to influence or control how a victim runs the llm command (e.g., via shared scripts, documentation snippets, or messages).
  • Trigger point: Execution of llm with a malicious payload passed to the --functions argument.
  • Why exploitation is possible: The input supplied to --functions is treated as trusted Python source and executed via exec() 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 --functions or 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() and eval() 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.

Sources

SourceLink
github.comgithub.com/simonw/llm
notion.sonotion.so/CVE-2026-31236-35d1e139318881a4a0f1fffcf671f7e3
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-31236
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2476636
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-31236.json

Frequently asked

questions

It is not remotely exploitable in a network-service sense; an attacker cannot trigger it over a network without user interaction. However, an attacker can provide a malicious llm command line (e.g., in documentation, chat, or scripts) and rely on social engineering to get a victim to execute it locally, which leads to code execution.

The attacker gains the same level of access as the user running the llm CLI. This usually means full control of the user's account context, including the ability to read and modify files, run other programs, and access the user's network resources and credentials.

The safest pattern is to avoid executing user-supplied code entirely in the main process. Instead, provide controlled extension points using whitelisted operations, declarative configurations, or isolated execution environments that run with reduced privileges and do not expose full interpreter capabilities.

When designing extensibility features, assume all user input (including configuration, flags, and scripts) is untrusted. Avoid exec()/eval() on this data, prefer declarative or restricted DSLs, apply least privilege and isolation to any dynamic behavior, and enforce secure coding guidelines and static analysis checks in development workflows.

Find out what's already
exploitable in your codebase.