交互式 JavaScript REPL
Deno Sandbox 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.
sandbox.deno.repl() 方法可以用于在沙箱中提供交互式的 Deno REPL。
此示例展示了如何在沙箱中启动一个 Deno REPL 并交互式地执行代码。
import { Sandbox } from "@deno/sandbox";
await using sandbox = await Sandbox.create();
// 启动一个 Deno REPL
const repl = await sandbox.deno.repl();
// 交互式执行代码,保持状态
await repl.eval("const x = 42;");
await repl.eval("const y = 8;");
const result = await repl.eval("x + y");
console.log("result:", result); // 50
For more information, see the Deno Sandbox documentation.