Summary
LMDeploy versions 0.12.3 and earlier enable arbitrary code execution by hardcoding trust_remote_code=True when loading HuggingFace models.
If an attacker can influence the remote model repository or redirect model references, they can execute malicious Python code within the LMDeploy process.
Affected context
This vulnerability appears in LMDeploy environments that load models from HuggingFace or similar hubs using code paths where trust_remote_code=True is hardcoded.
It is most relevant in scenarios where model identifiers or repositories can be controlled, swapped, or tampered with by less-trusted parties, such as multi-tenant model hubs, shared experimentation environments, or automated pipelines that fetch models dynamically.
The issue manifests during model initialization, when LMDeploy invokes the underlying HuggingFace APIs that permit execution of remote Python code as part of model loading.
Exploit preconditions
- Attack surface: Model loading and deployment workflows using LMDeploy.
- Required access: Ability to control or tamper with the referenced model repository (e.g., publishing a malicious model, altering configuration, or influencing the model name/URL used by LMDeploy).
- Trigger point: A vulnerable LMDeploy process loads a model via a call site that sets
trust_remote_code=True, causing remote Python modules to be imported and executed. - Why exploitation is possible: Hardcoded trust of remote code bypasses local validation and treats repository-provided Python modules as inherently safe, allowing an attacker to embed arbitrary executable code in the model package.
Why this happens
The core issue stems from a code injection pattern where untrusted, remotely hosted Python code is implicitly treated as trusted application logic.
LMDeploy's model-loading integrations with HuggingFace hardcode trust_remote_code=True, instructing the library to execute Python modules that are shipped alongside the model.
This aligns with CWE-94: Improper Control of Generation of Code, because the application fails to restrict or validate code obtained from external sources before execution, effectively allowing attackers to inject arbitrary behavior through the model artifacts.
Potential impact
- Execution of arbitrary Python code within the LMDeploy service or worker process.
- Compromise of the host running LMDeploy, including access to environment variables, credentials, and attached data stores.
- Unauthorized access to or exfiltration of model weights, prompts, user inputs, and inference outputs.
- Lateral movement inside the broader hosting environment, depending on LMDeploy's runtime permissions.
- Service disruption or sabotage, such as model backdooring, response manipulation, or denial-of-service behavior.
General mitigation guidance
Mitigation generally focuses on reducing trust in remote code and tightening the execution boundary between model data and application logic.
Common defensive patterns include:
- Avoiding or disabling
trust_remote_codesemantics wherever possible, preferring pure data-only model formats that do not require executing arbitrary Python modules. - Restricting model sources to vetted, internally mirrored, or cryptographically verified repositories, and treating external model hubs as untrusted by default.
- Introducing explicit allow-lists for model repositories or authors whose code is permitted to run in deployment environments.
- Running LMDeploy in hardened, least-privilege sandboxes (e.g., containers with minimal filesystem and network access, reduced OS capabilities, and segregated secrets).
- Separating model loading from critical infrastructure components so that compromise of one worker has limited blast radius.
How teams detect issues like this
Detection can focus on both source-level configuration and runtime behavior.
Useful approaches include:
- Static analysis or grep-based checks that flag
trust_remote_code=Trueusages in LMDeploy integrations, configuration scripts, or wrappers. - Code review practices that treat any remote code execution features in model loaders as security-sensitive and require explicit justification and architectural safeguards.
- Policy-based enforcement in CI/CD pipelines that block deployments when disallowed flags or risky model-loading patterns are detected.
- Runtime monitoring for anomalous behavior from LMDeploy processes, such as unexpected outbound network connections, file writes, or process spawning during or immediately after model loading.
- Periodic inventory of deployed models and their sources to identify unapproved or newly added repositories with executable components.

