Vercel Sandbox 支持在创建时设置环境变量

1 分钟阅读
2026 年 3 月 3 日
Vercel Sandbox 的 SDK 和 CLI 现已支持在创建 sandbox 时设置环境变量,并自动对每一条命令生效。
在 Vercel Sandbox 中执行多步骤流程(例如安装依赖、构建项目或启动开发服务器)时,每一步通常都需要相同的环境变量。现在,这些变量会在每次 runCommand 调用中自动可用。
await using sandbox = await Sandbox.create({ env: { HELLO: "world", DEBUG: "true" },});// Prints "world" (inherited from Sandbox.create)await sandbox.runCommand({ cmd: "node", args: ["-p", "process.env.HELLO"] });// Prints "false" (overrides the DEBUG value)await sandbox.runCommand({ cmd: "node", args: ["-p", "process.env.DEBUG"], env: { DEBUG: "false" } });
通过 Sandbox.create() 传入的环境变量会被所有命令自动继承。若有需要,也仍可在 runCommand 的单次调用中通过 per-command env 覆盖某个具体变量。
请更新到最新版 Sandbox CLI 和 SDK,运行 npm i @vercel/sandbox 即可开始使用。
原文链接:https://vercel.com/changelog/vercel-sandbox-now-accepts-environment-variables-at-creation

