Access string and binary output
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 access string and binary output from commands in a sandbox.
import { Sandbox } from "@deno/sandbox";
await using sandbox = await Sandbox.create();
// Get both string and binary data
const result = await sandbox.sh`cat binary-file.png`
.stdout("piped");
console.log("Binary length:", result.stdout!.length);
console.log("Text length:", result.stdoutText!.length);
// Use the binary data
import fs from "node:fs";
fs.writeFileSync("output.png", result.stdout!);
For more information about Sandboxes, see the Sandboxes documentation.