Skip to content

Fixes env vars in languages other than Python#108

Merged
jakubno merged 28 commits into
mainfrom
environment-variables-are-not-accessible-when-running-r-code-e2b-1977
Jul 9, 2025
Merged

Fixes env vars in languages other than Python#108
jakubno merged 28 commits into
mainfrom
environment-variables-are-not-accessible-when-running-r-code-e2b-1977

Conversation

@mishushakov

@mishushakov mishushakov commented May 14, 2025

Copy link
Copy Markdown
Member

Changelog:

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: [],
}

@linear

linear Bot commented May 14, 2025

Copy link
Copy Markdown

@mishushakov mishushakov self-assigned this May 14, 2025
@mishushakov mishushakov added the improvement Improvement for current functionality label May 14, 2025
Comment thread template/server/messaging.py Outdated
@mlejva

mlejva commented May 15, 2025

Copy link
Copy Markdown
Member

@mishushakov can you add tests for this case? it would be good to catch if setting env var breaks

@mishushakov

Copy link
Copy Markdown
Member Author

yes, these will be in a separate PR as otherwise we would be unable to merge this (the CI is using deployed template version)

@jakubno jakubno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not setting global env vars for the default context. Can you try to create the context in lifespan in server instead of the startup script, so we can make in all cleaner?

Can you clean up 0001_envs.py from template? it shouldn't be used anymore

@mishushakov mishushakov requested a review from jakubno June 3, 2025 14:58
@mishushakov

Copy link
Copy Markdown
Member Author

Let's wait for #116 here

@jakubno jakubno left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests to this PR? 🙏🏻

Comment thread template/server/contexts.py Outdated
@mishushakov

Copy link
Copy Markdown
Member Author

I need to rewrite the tests. I don't know what went south last time, but they don't look correct to me.

@mishushakov

Copy link
Copy Markdown
Member Author

Env vars set during build:

Screenshot 2025-06-06 at 19 30 49

@jakubno

jakubno commented Jun 10, 2025

Copy link
Copy Markdown
Member

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])

@mishushakov mishushakov requested a review from jakubno July 8, 2025 15:30
Comment thread template/server/main.py
@jakubno jakubno merged commit 8511114 into main Jul 9, 2025
6 checks passed
@jakubno jakubno deleted the environment-variables-are-not-accessible-when-running-r-code-e2b-1977 branch July 9, 2025 11:43
mishushakov added a commit that referenced this pull request Jul 9, 2025
jakubno pushed a commit that referenced this pull request Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improvement for current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Environment variables inaccessible in javascript/typescript Environment Variables are not Accessible when running R code in sandbox

3 participants