Fixes env vars in languages other than Python
Changelog:
- closes https://github.com/e2b-dev/E2B/issues/665
- runs a code cell to set env variables if any env variables are set (either sandbox-level or per cell)
- note: os.environ.set_envs_for_execution function might no longer be required?
Example:
import { Sandbox } from "@e2b/code-interpreter";
const sbx = await Sandbox.create({ debug: true });
const code = await sbx.runCode(`console.log(process.env.TEST);`, {
language: "javascript",
envs: { TEST: "hello" },
});
console.log(code.logs);
Before:
{
stdout: [ "undefined\n" ],
stderr: [],
}
After:
{
stdout: [ "hello\n" ],
stderr: [],
}
@mishushakov can you add tests for this case? it would be good to catch if setting env var breaks
yes, these will be in a separate PR as otherwise we would be unable to merge this (the CI is using deployed template version)
Let's wait for #116 here
I need to rewrite the tests. I don't know what went south last time, but they don't look correct to me.
Env vars set during build:
Env vars set during build:
I don't think this is correct, try this:A
from e2b_code_interpreter import Sandbox
sbx = Sandbox(envs={"TEST": "ABC"})
execution = sbx.run_code(
"""
import os
os.getenv("TEST")
"""
)
print(execution.results[0])