Skip to content

Commit

Permalink
Document E2B_SANDBOX env var (#538)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva authored Jan 14, 2025
2 parents 4552eb3 + 8b8c979 commit 1108879
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
# Setting environment variables
# 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

<Note>
Sometimes it's useful to know if you are inside a sandbox. Upon creating a sandbox, an environment variable `E2B_SANDBOX` is set to `true`.
</Note>

<CodeGroup>
```js
const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('echo $E2B_SANDBOX')
```
```python
sandbox = Sandbox()
result = sandbox.run_code("import os; os.getenv('E2B_SANDBOX')")
```
</CodeGroup>


---

## Setting environment variables
There are 3 ways to set environment variables in a sandbox:
1. [Global environment variables when creating the sandbox](/docs/sandbox/environment-variables#1-global-environment-variables-when-creating-the-sandbox).
2. [When running code in the sandbox](/docs/sandbox/environment-variables#2-setting-environment-variables-when-running-code).
3. [When running commands in the sandbox](/docs/sandbox/environment-variables#3-setting-environment-variables-when-running-commands).


## 1. Global environment variables
### 1. Global environment variables
You can set global environment variables when creating a sandbox.

<CodeGroup>
Expand All @@ -30,7 +52,7 @@ sandbox = Sandbox(
```
</CodeGroup>

## 2. Setting environment variables when running code
### 2. Setting environment variables when running code
You can set environment variables for specific code execution call in the sandbox.

<Note>
Expand All @@ -57,7 +79,7 @@ result = sandbox.run_code(
```
</CodeGroup>

## 3. Setting environment variables when running commands
### 3. Setting environment variables when running commands
You can set environment variables for specific command execution in the sandbox.

<Note>
Expand All @@ -82,4 +104,4 @@ sandbox.commands.run(
} # $HighlightLine
)
```
</CodeGroup>
</CodeGroup>

0 comments on commit 1108879

Please sign in to comment.