const sandbox = new Cu.Sandbox('http://example.com'); const result = Cu.evalInSandbox('3 + 4', sandbox); console.log(result); // Output: 7
const sandbox = new Cu.Sandbox('http://example.com'); sandbox.console = { log: (message) => { alert(message); } }; Cu.evalInSandbox('console.log("Hello, world!");', sandbox);This example creates a new sandbox and adds a custom `console` object to it. The `console.log` function is overridden with an implementation that shows an alert dialog. The `evalInSandbox` function is then used to execute a script that logs a message to this custom console. The `Cu` in the examples stands for the `Components.utils` module of the Mozilla XPCOM library. This library provides various low-level utilities for writing add-ons and extensions for Mozilla-based applications like Firefox and Thunderbird. So, the `evalInSandbox` function is part of this library.