Skip to content

Security: Make trust_remote_code configurable with safe default#3642

Open
deosha wants to merge 1 commit intonomic-ai:mainfrom
deosha:fix/trust-remote-code-security
Open

Security: Make trust_remote_code configurable with safe default#3642
deosha wants to merge 1 commit intonomic-ai:mainfrom
deosha:fix/trust-remote-code-security

Conversation

@deosha
Copy link

@deosha deosha commented Jan 12, 2026

Summary

This PR addresses a security concern in the training scripts where trust_remote_code=True is hardcoded when loading models via HuggingFace transformers.

Changes:

  • Make trust_remote_code configurable via the config file (default: False)
  • Add warning message when trust_remote_code=True is enabled
  • Applied to both train.py and inference.py

Security Context

The trust_remote_code=True parameter allows arbitrary Python code execution from model repositories. While this is sometimes necessary for custom model architectures, it poses a security risk if:

  • Users load models from untrusted sources
  • A trusted model repository is compromised

By making this configurable with a safe default, users must explicitly opt-in to this behavior.

Identified using aisentry.

Usage

To enable trust_remote_code when needed, add to your config:

trust_remote_code: true

Test plan

  • Verify training works with default config (trust_remote_code=False) for standard models
  • Verify training works with trust_remote_code=True for models that require it
  • Confirm warning message appears when trust_remote_code is enabled

The trust_remote_code=True parameter in AutoModelForCausalLM.from_pretrained()
allows arbitrary Python code execution from model repositories. This is a
security risk as malicious model repos could execute arbitrary code.

Changes:
- Make trust_remote_code configurable via config file (default: False)
- Add warning message when trust_remote_code is enabled
- Affected files: train.py, inference.py

Users who need trust_remote_code for specific models can enable it by adding
`trust_remote_code: true` to their config file.

Identified using aisentry: https://aisentry.co

Signed-off-by: Deo Shankar <deo@Deos-MacBook-Pro.local>
@deosha deosha force-pushed the fix/trust-remote-code-security branch from 7a89b0f to c415798 Compare January 12, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant