Skip to content

fix(core): correct misleading jinja2 sandboxing comment#35183

Merged
Mason Daugherty (mdrxy) merged 1 commit intolangchain-ai:masterfrom
sumleo:fix/jinja2-sandboxing-comment
Feb 17, 2026
Merged

fix(core): correct misleading jinja2 sandboxing comment#35183
Mason Daugherty (mdrxy) merged 1 commit intolangchain-ai:masterfrom
sumleo:fix/jinja2-sandboxing-comment

Conversation

@sumleo
Copy link
Contributor

Summary

  • The inline comment at langchain_core/prompts/string.py:67-69 incorrectly states that SandboxedEnvironment "blocks ALL attribute/method access" and that "only simple variable lookups like {{variable}} are allowed."
  • In reality, Jinja2's SandboxedEnvironment only blocks access to dunder attributes (__class__, __globals__, etc.) to prevent sandbox escapes. Regular attribute access like {{obj.content}} and method calls remain allowed.
  • This misleading comment was left behind when a _RestrictedSandboxedEnvironment class 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

  • No behavioral change — comment-only fix
  • Verified SandboxedEnvironment behavior matches updated comment

This PR was authored with the help of AI tools.

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.
@github-actions github-actions bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix external labels Feb 12, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 12, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 13 untouched benchmarks
⏩ 21 skipped benchmarks1


Comparing sumleo:fix/jinja2-sandboxing-comment (0532fe0) with master (6ac12b3)2

Open in CodSpeed

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on master (a50d86c) during the generation of this report, so 6ac12b3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@mdrxy Mason Daugherty (mdrxy) merged commit 6a07b3a into langchain-ai:master Feb 17, 2026
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external fix For PRs that implement a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants