Repository navigation
Description
Summary
Implement safer script evaluation by running user-defined scripts in a well-defined, restrictive execution environment.
Proposed Changes
1. Restrictive evaluation environment
Evaluate scripts in a well-defined restrictive environment that only includes access to:
refs- Bundled libraries
statequeueEventsaddEvents
2. New script registration interface
Introduce a new interface for script execution: register a script snippet as a function that gets written out to utils/scripts.js. This provides a centralized, inspectable location for all registered script functions.
3. Python-side Var for the execution environment
Create a python-side Var that represents the execution environment, so that script snippets can reference names like refs or addEvents correctly and with proper type awareness.
Direction after #7794 (from the review)
Now that the frontend runtime lives in its own package (#7609, #7794), this is the next direction for that work: untangle script evaluation and find the best way to safely eval scripts.
- A controlled environment that exposes a limited, well-defined API to scripts (the list above), with the ability to poke through additional libraries, like the mechanism dynamic components use for bundled libraries.
- Expose that environment object to the Python side with a typed helper (item 3 above), so calling the APIs stays reliable as the actual JS code moves around.
- Keep a "legacy" (dangerous) eval environment alongside it, based on the current
state.jsimports, so existing scripts keep working while they migrate. - Once both environments exist, start deconstructing
state.jsand really cleaning up the frontend code. Today event code iseval'd insidestate.jsand resolves names from its module scope, so moving functions out needs an integration test for that contract first (noted in Move the frontend javascript into its own package, reflex-frontend #7794).
Related: #7860 (direct eval in state.js stops minification of the shared chunk).
Cycle 166 acceptance
Show a Reflex app author can register and call a direct JavaScript snippet through the documented Python-facing interface. Verify the intended restricted API with benign integration tests and keep a regression test for the existing script path during migration.
Activity
linear commentedon Mar 24, 2026
ENG-9127