improve: enforce STRANDS_TRUST_REMOTE_CODE gate in policy factory#92
Open
cagataycali wants to merge 1 commit intostrands-labs:mainfrom
Open
improve: enforce STRANDS_TRUST_REMOTE_CODE gate in policy factory#92cagataycali wants to merge 1 commit intostrands-labs:mainfrom
cagataycali wants to merge 1 commit intostrands-labs:mainfrom
Conversation
The docstring for create_policy() mentioned STRANDS_TRUST_REMOTE_CODE but there was no actual enforcement — the env var was never checked. This commit: - Adds _check_trust_remote_code() that raises UntrustedRemoteCodeError when a provider listed in _HF_REMOTE_CODE_PROVIDERS is used without STRANDS_TRUST_REMOTE_CODE being set to 1/true/yes. - Currently gates 'lerobot_local' (the only provider that calls trust_remote_code=True on HuggingFace model loading). - Mock, groot, lerobot_async, and runtime-registered providers are NOT gated — only providers that actually download+execute remote model code. - Exports UntrustedRemoteCodeError from strands_robots.policies. - Updates tests to use monkeypatch for the env var where needed. - Adds dedicated TestTrustRemoteCodeGate test class.
f297922 to
53668fd
Compare
mrgh-test
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
create_policy()docstring referencesSTRANDS_TRUST_REMOTE_CODEas a mechanism for users to acknowledge the risk of loading HuggingFace models withtrust_remote_code=True, but the environment variable was never actually checked — the warning was documentation-only.This PR makes the gate real.
Changes
_check_trust_remote_code(provider)— new helper that raisesUntrustedRemoteCodeErrorwhen a provider may execute HF remote code andSTRANDS_TRUST_REMOTE_CODEis not set to1/true/yes.create_policy(): runtime registry, smart-string resolution, and standard JSON lookup.mock,lerobot_async,groot) are allowlisted and skip the check since they never download/execute remote model code.UntrustedRemoteCodeErroris a new public exception for downstream error handling.Usage
Motivation
HuggingFace's
trust_remote_code=Trueallows arbitrary Python execution from model repositories. Making users explicitly opt in is a standard practice (HF itself does this intransformers). This brings our policy factory in line with that pattern.