Description
Describe the bug
Similar to this other issue, environment variables aren't accessible in Javascript or Typescript code running in the sandbox.
To Reproduce
Steps to reproduce the behavior:
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create({envs: {MY_VAR:'global_value'}});
console.log(await sandbox.runCode(`console.log(process.env.MY_VAR);`, {language: 'js', envs: {MY_VAR:'env_value'}}));
results in something like:
Execution {
results: [],
logs: { stdout: [ 'undefined\n' ], stderr: [] },
error: undefined,
executionCount: 4
}
The following two worked:
await sandbox.files.write('/home/user/.env', 'MY_VAR=file_value');
console.log(await sandbox.runCode(`
require('dotenv').config();
console.log(process.env.MY_VAR);
`, {language: 'js', envs: {MY_VAR:'local_value'}}));
or
await sandbox.commands.run(`node -e "console.log(process.env.MY_VAR)");`, {envs: { MY_VAR: '123' }});
This works fine if the code passed in runCode() is python.