Skip to main content
Set environment variables in your sandbox. You can set individual variables or replace all variables at once.

Overview

Setting environment variables is essential for:
  • Configuring application settings
  • Providing API keys and secrets
  • Setting up database connections
  • Configuring runtime behavior
set_all() replaces ALL existing environment variables. Use Updating Environment Variables if you want to merge with existing variables instead.

Set Single Variable

Set a single environment variable:

Set Multiple Variables

Set multiple environment variables at once:

Replace All Variables

Replace all environment variables (removes existing ones):

Use in Code Execution

Set variables and use them in code:

Use in Commands

Set variables and use them in shell commands:

Complete Example

Here’s a complete example showing environment variable setup:

Best Practices

1

1. Use set() for Single Variables

Use env.set(key, value) for setting individual variables. This merges with existing variables.
2

2. Use set_all() Carefully

set_all() replaces ALL variables. Only use when you want to completely replace the environment.
3

3. Prefer update() for Multiple Variables

For setting multiple variables while preserving existing ones, use Updating Environment Variables instead.
4

4. Set Before Execution

Set environment variables before running code or commands that need them.
5

5. Verify After Setting

Always verify variables are set correctly using get() or get_all() after setting.

Next Steps