Skip to main content

为沙箱提供 SSH 访问权限

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.

sandbox.exposeSsh() 方法可以用来为沙箱提供 SSH 访问权限。

import { Sandbox } from "@deno/sandbox";

await using sandbox = await Sandbox.create();

// 获取 SSH 凭据
const { hostname, username } = await sandbox.exposeSsh();
console.log(`ssh ${username}@${hostname}`);

// 通过睡眠保持进程存活,否则脚本退出时沙箱将被销毁。
await new Promise((resolve) => setTimeout(resolve, 10 * 60 * 1000)); // 10 分钟

For more information about Sandboxes, see the Sandboxes documentation.

你找到了你需要的东西吗?

编辑此页面
隐私政策