๐Ÿ›ก๏ธ 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

  1. โš™๏ธ Compile: Parses JS & catches syntax errors.
  2. ๐Ÿ“ฅ Load: Mounts compiled scripts to the environment.
  3. ๐Ÿƒ Run: Executes the entrypoint with injected globals.
  4. ๐Ÿงน 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).