Summary
A critical code injection vulnerability in Xinference allows attacker-influenced Llama3 tool-call output to be evaluated as Python code. An unauthenticated remote attacker may craft a prompt that causes the model-generated expression to execute commands in the Xinference server process context when tool-enabled chat requests are processed.
Affected context
The vulnerability occurs in Xinference deployments that expose the chat completions API with tool-calling support enabled and use the affected Llama3 tool-output processing path. Risk arises when model-generated tool-call arguments are treated as executable Python expressions during non-streaming or post-processed completion handling, rather than being parsed strictly as data.
Exploit preconditions
- Attack surface: The remotely accessible
/v1/chat/completionsAPI - Required access: No authentication may be required when the endpoint is exposed without access controls
- Trigger point: Processing a tool-enabled chat completion and extracting Llama3 tool calls
- Attacker influence: A crafted prompt can influence model-generated tool-call output
- Why exploitation is possible: The resulting expression is passed to Python
eval()without sufficiently restricting its contents or execution behavior
Why this happens
The underlying flaw is the use of dynamic Python evaluation on data derived from model output. In the affected tool parser and completion-processing paths, an attacker can influence a generated expression that is subsequently evaluated as executable code. This behavior maps to CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code, because input that should remain data is interpreted as Python instructions.
Potential impact
- An attacker may execute arbitrary commands in the Xinference server process context
- The attacker could access or alter data available to that process
- The affected service may be used to compromise connected model, storage, or network resources
- Service availability could be disrupted through unauthorized process activity
- Credentials or secrets accessible to the service may be exposed
General mitigation guidance
Mitigation generally focuses on eliminating dynamic evaluation of model- or user-influenced content.
Common defensive patterns include:
- Replacing
eval()with strict, data-only parsing and explicit schema validation - Allowing only predefined tool names, argument types, and structured values
- Treating model output as untrusted input regardless of the model's source or deployment
- Applying authentication, authorization, rate limits, and network restrictions to inference endpoints
- Running inference workers with least privilege and limiting filesystem, credential, and network access
- Separating model-serving processes from sensitive control-plane resources
How teams detect issues like this
Detection programs commonly look for:
- Static-analysis findings involving
eval(), dynamic execution, or equivalent interpreter APIs - Data-flow paths from HTTP request content or model output into evaluation functions
- Code-review signals where tool-call arguments are converted into executable expressions
- Tests that submit adversarial or unexpected tool-call structures and verify that they remain inert data
- API policy checks confirming that tool-enabled inference endpoints require appropriate authentication and authorization
Automated code-review and software-composition tools may help identify dynamic execution patterns, but findings should be validated against the complete request-to-parser data flow.

