Skip to main content

Evaluating JavaScript

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.

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.deno.eval(`
  const a = 1;
  const b = 2;
  a + b;
`);
console.log("result:", result);

For more information, see the Deno Sandbox documentation.

Did you find what you needed?

Privacy policy