Evaluating JavaScript
Deno Sandboxes provide a sandboxed environment for evaluating JavaScript code. This is useful for evaluating code that is not trusted or for testing code that is not safe to run in the main runtime.
You can evaluate JavaScript code in a sandbox using the eval function.
import { Sandbox } from "@deno/sandbox";
await using sandbox = await Sandbox.create();
const result = await sandbox.eval(`
const a = 1;
const b = 2;
a + b;
`);
console.log("result:", result);
For more information about Sandboxes, see the Sandboxes documentation.