๐ก๏ธ Execution Sandboxing & Lifecycle
๐ Sandbox Creation
- ๐ Iframe Isolation:
sandbox="allow-scripts" blocks parent access, cookies, and local storage.
- โ๏ธ Context Lock: Global scope is isolated via a shadow iframe; sensitive APIs are frozen using
Object.defineProperty.
๐ Script Lifecycle
- โ๏ธ Compile: Parses JS & catches syntax errors.
- ๐ฅ Load: Mounts compiled scripts to the environment.
- ๐ Run: Executes the entrypoint with injected globals.
- ๐งน Teardown: Kills dangling intervals, timeouts, workers, and event listeners.
- ๐จ Timeout Guard: Web Worker monitor or generator loop counter terminates infinite loops by force-recreating the sandbox.
๐ State Syncing
- ๐จ Protocol:
postMessage transfers serialized data/errors (execution_event).
- โ ๏ธ Limits: Standard
structuredClone rules apply (no functions/DOM nodes).