Summary
LMDeploy versions 0.12.3 and earlier enable remote model code execution by hardcoding trust_remote_code=True when loading models from Hugging Face.
This behavior allows unreviewed, repository-supplied Python code to run automatically during model loading, enabling supply-chain remote code execution when an attacker can control or tamper with the upstream model repository.
Affected context
This vulnerability affects environments that use LMDeploy (up to and including 0.12.3) to download and serve models from remote repositories such as Hugging Face Hub.
The risk is most pronounced when:
- Model repositories are not fully trusted or are controlled by third parties
- There is no manual review of repository code prior to deployment
- LMDeploy runs in environments with meaningful network, file system, or data access
Because trust_remote_code=True is hardcoded, users do not need to explicitly opt in before remote code from the model repository is executed.
Exploit preconditions
- Attack surface: Model loading and deployment workflow that pulls models from remote repositories (e.g., Hugging Face Hub).
- Required access: Ability to publish, modify, or tamper with the target model repository (legitimately or via repository compromise).
- Trigger point: LMDeploy's model initialization step, where the toolkit automatically executes repository-provided Python code with
trust_remote_code=True. - Why exploitation is possible: Hardcoded trust of remote repository code bypasses user consent and validation, allowing arbitrary Python to run as part of model loading without interactive approval.
Why this happens
The underlying issue is unconditional execution of untrusted remote code as part of the model loading process, which maps to CWE-94: Improper Control of Generation of Code ('Code Injection').
By hardcoding trust_remote_code=True, LMDeploy implicitly treats remote repository content as trusted, executable logic rather than as untrusted model data.
This design also aligns with CWE-915 (Improperly Controlled Modification of Dynamically-Determined Object Attributes) and CWE-1188 (Insecure Default Initialization of Resource), because dynamic model components are instantiated from remote code under insecure default settings without explicit user opt-in or restrictive sandboxing.
Potential impact
- Remote code execution under the privileges of the LMDeploy process
- Compromise of the host running LMDeploy, including access to local files and environment secrets
- Lateral movement within the serving infrastructure or cluster if additional privileges are available
- Exfiltration or tampering of sensitive model inputs, outputs, or training data
- Supply-chain compromise of downstream systems that rely on the affected model service
General mitigation guidance
Effective mitigation focuses on treating remote model repositories as untrusted code sources and tightening defaults around execution:
- Prefer loading models in a mode that does not execute remote repository code by default, and require explicit, documented opt-in where truly necessary.
- Introduce a clear trust boundary between model weights (data) and model implementation (code), avoiding automatic execution of repository-provided Python where possible.
- Run LMDeploy and related inference workloads with least privilege, using restricted filesystem access, minimized environment variables, and locked-down network egress.
- Where execution of remote code cannot be avoided, consider sandboxing (containers, VMs, seccomp, or similar) to constrain potential RCE impact.
- Establish an internal review process for any model repository whose code will be executed, treating it like third-party software with code review and provenance checks.
How teams detect issues like this
Detection typically combines code-level analysis with operational monitoring:
- Use static analysis or configuration review to identify hardcoded
trust_remote_code=Trueor equivalent unsafe defaults in model tooling and deployment scripts. - Add CI policy checks that flag or block merges when remote code execution flags are enabled without justification.
- Implement runtime monitoring and logging around model loading paths, capturing when and from where code is fetched and executed.
- Review infrastructure audit logs for unexpected outbound network connections, unusual file access, or process behaviors originating from LMDeploy containers or hosts.
- Employ software composition analysis (SCA) and supply-chain scanning tools to identify components that automatically execute remote code as part of their normal operation.

