Environment variables
Default environment variables
Upon creating a sandbox, useful sandbox metadata is set as environment variables for commands:E2B_SANDBOXis set totruefor processes to know if they are inside our VM.E2B_SANDBOX_IDto know the ID of the sandbox.E2B_TEAM_IDto know the team ID that created the sandbox.E2B_TEMPLATE_IDto know what template was used for the current sandbox.
These default environment variables are only accessible via the SDK, when using the CLI you can find them in the form of dot files in the
/run/e2b/ dir: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.- These environment variables are scoped to the command but are not private in the OS.
- If you had a global environment variable with the same name, it will be overridden only for the command.
3. Setting environment variables when running commands
You can set environment variables for specific command execution in the sandbox.- These environment variables are scoped to the command but are not private in the OS.
- If you had a global environment variable with the same name, it will be overridden only for the command.
Storage buckets
To connect a bucket for storing data from the sandbox, you can use the FUSE file system to mount the bucket inside the sandbox. You will need to create a custom sandbox template with the FUSE file system installed. The guide for building a custom sandbox template can be found here.Google Cloud Storage
Prerequisites
To use Google Cloud Storage, you’ll need a bucket and a service account. You can create a service account here and a bucket here. If you want to write to the bucket, make sure the service account has theStorage Object User role for this bucket.
You can find a guide on creating a service account key here.
Mounting the bucket
To use the Google Cloud Storage we need to install thegcsfuse package. There’s simple template that can be used to create a container with the gcsfuse installed.
gcsfuse command.
Flags
The complete list of flags is available here.Allow the default user to access the files
To allow the default user to access the files, we can use the following flags:Amazon S3
To use Amazon S3, we can use thes3fs package. The template setup is similar to that of Google Cloud Storage.
s3fs command is used to mount the bucket to the sandbox.