`trust_remote_code=True` is hard-coded in the Hugging Face and vLLM wrappers and cannot be turned off

Open
#389 0 comments 0 reactions 0 assignees View on GitHub

@ningyixi is already working on this.

Since Nov 30, 2026.

  • #390 by @ningyixi — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
huggingface, python

Research direction

The hard-coded trust_remote_code=True sits in lagent/llms/huggingface.py (tokenizer and model from_pretrained calls), lagent/llms/vllm_wrapper.py (LLM(...) and AsyncEngineArgs(...)), and lagent/actions/web_visitor.py (tokenizer load). Start by reading how model_kwargs and tokenizer_kwargs are merged into those calls, since that is where the duplicate-keyword TypeError comes from. Done means both parameters are exposed on the four classes and forwarded to every call, and the default stays True. The design of the parameter names and defaults should be confirmed with maintainers first.

Written by the indexing model from the issue text.

Description

The local model wrappers always pass trust_remote_code=True, with no way for the caller to disable it and no way to pin a Hub revision:

Why it matters

  • With trust_remote_code=True, Transformers and vLLM import and run the Python files shipped in the model repo. Because no revision is pinned, that code is whatever the Hub repo's default branch holds at load time, so an update or a compromised upstream repo runs new code in the agent process.
  • Callers cannot opt out: passing trust_remote_code=False in model_kwargs / tokenizer_kwargs raises TypeError: got multiple values for keyword argument 'trust_remote_code'. That makes the wrappers unusable in setups that require it to be off, even for models that do not need custom code.

I understand trust_remote_code was added on purpose (#49, #50) so that InternLM and Qwen checkpoints load out of the box, so this is not a request to remove it.

Suggested fix

  • Add trust_remote_code: bool = True (keeping today's default) and revision: Optional[str] = None parameters to HFTransformer, VllmModel, AsyncVllmModel and WebVisitor, and forward both to every from_pretrained / LLM(...) call instead of the hard-coded keyword.
  • Document that a commit hash for revision is recommended whenever trust_remote_code is on.

Found with lacan-scan v7.6.4 (rule AIS203), checked by hand.

Dominant language
Python
Stars
2.3k
Forks
249
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from InternLM/lagent

All issues in InternLM/lagent

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.