fix(core): correct misleading jinja2 sandboxing comment#35183
Conversation
The inline comment incorrectly stated that SandboxedEnvironment blocks ALL attribute/method access. In reality, it only blocks dunder attribute access (__class__, __globals__, etc.) to prevent sandbox escapes. Regular attribute access and method calls are still allowed. This comment was left behind when a _RestrictedSandboxedEnvironment class was reverted in commit 395c8d0. The function's docstring already correctly warns against using untrusted templates.
Merging this PR will not alter performance
|
6a07b3a
into
langchain-ai:master
Summary
langchain_core/prompts/string.py:67-69incorrectly states thatSandboxedEnvironment"blocks ALL attribute/method access" and that "only simple variable lookups like{{variable}}are allowed."SandboxedEnvironmentonly blocks access to dunder attributes (__class__,__globals__, etc.) to prevent sandbox escapes. Regular attribute access like{{obj.content}}and method calls remain allowed._RestrictedSandboxedEnvironmentclass was reverted in commit 395c8d0. Updated to accurately describe the actual behavior.Why this matters
The comment could mislead developers into trusting partially-untrusted templates, believing attribute access is blocked when it is not. The function's docstring already correctly warns against untrusted templates.
Test plan
SandboxedEnvironmentbehavior matches updated comment