Environment variables
This page covers how to set and use environment variables in a sandbox, and default environment variables inside the sandbox.
Default environment variables
Knowing if you are inside a sandbox
Sometimes it’s useful to know if the code is running inside a sandbox. Upon creating a sandbox, an environment variable E2B_SANDBOX
is automatically set to true
.
You can try it out by running the following code in the sandbox:
Setting environment variables
There are 3 ways to set environment variables in a sandbox:
- Global environment variables when creating the sandbox.
- When running code in the sandbox.
- When running commands in the sandbox.
1. Global environment variables
You can set global environment variables when creating a sandbox.
2. Setting environment variables when running code
You can set environment variables for specific code execution call in the sandbox.
If you had a global environment variable with the same name, it will be overridden.
3. Setting environment variables when running commands
You can set environment variables for specific command execution in the sandbox.
If you had a global environment variable with the same name, it will be overridden.