You are reading a legacy (pre v1.0) document.
Setting environment variables
Global environment variables
You can set the sandbox's global environment variables when initializing a new sandbox.
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create({
template: 'base',
envVars: {FOO: 'Hello'},
})
await sandbox.close()
Environment variables per process
Alternatively, you can set environment variables when starting a new process. These environment variables are accessible only for this process.
Environment variables set when starting a new process have precedence over the environment variables set when initializing the sandbox.
import { Sandbox } from 'e2b'
const sandbox = await Sandbox.create({
template: 'base',
envVars: {FOO: 'Hello'},
})
const proc = await sandbox.process.start({
cmd: 'echo $FOO $BAR!',
envVars: {BAR: 'World'},
})
await proc.wait()
console.log(proc.output.stdout)
// output: Hello World!
await sandbox.close()