```Deno 沙箱```
Deno Sandbox

原始链接: https://deno.com/blog/introducing-deno-sandbox

## Deno 沙箱:安全运行不受信任的代码 Deno Deploy 推出 **Deno 沙箱**,这是一种安全执行由 LLM(或任何不受信任的来源)生成代码的新方案,而不会损害系统安全。传统的沙箱不足以应对代码自动访问具有敏感凭据的 API 的情况;Deno 沙箱 直接解决了这个问题。 它利用轻量级的 Linux 微型虚拟机进行隔离,启动时间小于一秒,可通过 SSH、HTTP 或 VS Code 访问。至关重要的是,**密钥受到保护**:API 密钥从不存在于沙箱环境中,仅在批准的传出请求时才生成,从而防止数据泄露。网络出口也受到控制,阻止连接到未经授权的主机。 Deno 沙箱与 Deno Deploy 无缝集成——代码可以直接从沙箱部署到生产环境,只需一条命令,无需重建。它还通过卷和快照提供持久性选项,用于缓存和预安装的工具链。 Deno 沙箱现已进入 Beta 测试阶段,包含在 Deno Deploy 的按使用量计费的计划中。它非常适合 AI 代理、安全的插件系统以及处理用户提供的代码的环境。

## Deno 沙箱总结 Deno 沙箱为运行不受信任的代码提供了一个安全环境,特别是具有 API 访问权限的 LLM 生成代码,解决了密钥泄露的风险。它利用 Deno Deploy 云中的轻量级 Linux 微型虚拟机,并通过仅允许为批准的主机进行密钥替换来控制网络出口。 此外,还提供了一个 Python SDK。 其核心创新在于仅在向授权域名发出的外向请求期间,动态地将占位符替换为真实的 API 密钥,从而防止密钥被永久盗取。 然而,讨论中也指出了潜在的漏洞,例如通过 API 响应或 HTTP 标头进行密钥反射或操纵。 许多评论员注意到类似沙箱解决方案的激增(Modal、E2B 等),并质疑其与自托管 VM 相比的价值主张。 此外,人们还对博客文章的写作风格表示担忧,许多人怀疑是 AI 生成的。 价格也是一个争议点,一些人认为它明显高于传统的 VM 成本。
相关文章

原文

Over the past year, we’ve seen a shift in what Deno Deploy customers are building: platforms where users generate code with LLMs, and that code runs immediately without review. That code frequently calls LLMs itself, which means it needs API keys and network access.

This isn’t the traditional “run untrusted plugins” problem. It’s deeper: LLM-generated code, calling external APIs with real credentials, without human review. Sandboxing the compute isn’t enough. You need to control network egress and protect secrets from exfiltration.

Deno Sandbox provides both. And when the code is ready, you can deploy it directly to Deno Deploy without rebuilding.

Watch the full announcement video here.

Sandboxes?

You don’t want to run untrusted code (generated by your LLMs, your users LLMs, or even hand written by users) directly on your server. It will compromise your system, steal your API keys, and call out to evil.com. You need isolation.

Deno Sandbox gives you lightweight Linux microVMs (running in the Deno Deploy cloud) to run untrusted code with defense-in-depth security. You create or programmatically via our JavaScript or Python SDKs, and they boot in under a second. You can also interact with them via SSH, HTTP, or even open a VS Code window directly into the sandbox.

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

await using sandbox = await Sandbox.create();
await sandbox.sh`ls -lh /`;

Secrets That Can’t Be Stolen

But there is more. In Deno Sandbox, secrets never enter the environment. Code sees only a placeholder:

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

await using sandbox = await Sandbox.create({
  secrets: {
    OPENAI_API_KEY: {
      hosts: ["api.openai.com"],
      value: process.env.OPENAI_API_KEY,
    },
  },
});

await sandbox.sh`echo $OPENAI_API_KEY`;

The real key materializes only when the sandbox makes an outbound request to an approved host. If prompt-injected code tries to exfiltrate that placeholder to evil.com? Useless.

Network Egress Control

You can also restrict which hosts the sandbox can talk to:

await using sandbox = await Sandbox.create({
  allowNet: ["api.openai.com", "*.anthropic.com"],
});

Any request to an unlisted host gets blocked at the VM boundary.

Both features are implemented via an outbound proxy similar to coder/httpjail. This gives us a chokepoint for policy enforcement. We plan to add more capabilities here: analytics for outbound connections and programmatic hooks for trusted code to inspect or modify requests.

If you’re running untrusted JavaScript or TypeScript, combine this with Deno’s --allow-net flag for defense in depth: VM-level network restrictions plus runtime-level permissions.

Sandbox to Production

sandbox.deploy() deploys code from your sandbox directly to Deno Deploy.

const build = await sandbox.deploy("my-app", {
  production: true,
  build: { mode: "none", entrypoint: "server.ts" },
});

const revision = await build.done;
console.log(revision.url);

One call to go from sandbox to production deployment. No rebuilding in a different CI system, no re-authenticating with a different tool. Just turn your dev environment directly into a production ready, auto-scaling serverless deployment.

Persistence

Sandboxes are ephemeral by default, but when you need state we have you covered:

  • Volumes: read-write storage for caches, databases, user data
  • Snapshots: read-only images for pre-installed toolchains and volume base

Run apt-get install once, snapshot it, and every future sandbox boots with everything already installed. Create read-write volumes from the snapshots to create a fresh development environment in seconds.

Technical Details

Spec Value
Regions Amsterdam, Chicago
vCPUs 2
Memory 768 MB - 4 GB
Lifetime Ephemeral or timeout (supports extending on demand)
Max lifetime 30 minutes
Boot time

Perfect for AI agents executing code, vibe-coding environments, secure plugin systems, ephemeral CI runners, and customer-supplied code.

Pricing

Deno Sandbox is included in your Deno Deploy plan with competitive, usage-based pricing. You pay for compute time, not wall-clock time.

  • $0.05/h CPU time (40h included with Pro)
  • $0.016/GB-h memory (1000 GB-h included with Pro)
  • $0.20/GiB-month volume storage (5 GiB included with Pro)

See full pricing details →

Enterprise pricing available—contact [email protected].

Get Started

Deno Sandbox launches in beta today, alongside the general availability of Deno Deploy.

We’re excited to see what you (or your AI agents) build with Deno Sandbox.

联系我们 contact @ memedata.com