Environment Variables Now Available at Sandbox Creation
Vercel has enhanced its Sandbox SDK and CLI with support for setting environment variables at sandbox creation time. This feature streamlines workflows that involve multiple sequential commands requiring the same environment configuration.
What Changed
When creating a Sandbox instance, developers can now pass environment variables via the env parameter:
await using sandbox = await Sandbox.create({
env: { HELLO: "world", DEBUG: "true" },
});
These environment variables are automatically inherited by every subsequent runCommand call, eliminating the need to redeclare them for each step.
Flexibility and Override Support
While environment variables are inherited from sandbox creation, the feature maintains flexibility:
- Inheritance: All environment variables passed to
Sandbox.create()are available to every command - Per-command overrides: Individual
runCommandcalls can still override specific environment variable values when needed
Getting Started
Developers can update to the latest version with:
npm install @vercel/sandbox
This enhancement is particularly useful for multi-step processes like installing dependencies, building projects, or starting development servers, where maintaining consistent configuration across steps is critical.