Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Pass env vars with commands

Tomas Valenta0143ff25f2c3
diff --git a/api-service/app.py b/api-service/app.py
index c28f41cd6..f0064a71f 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -1,5 +1,6 @@
import os
import uuid
+from codegen.tools.playground.tools.process import encode_command_output
from dotenv import load_dotenv
from typing import List
diff --git a/api-service/session/env.py b/api-service/session/env.py
index d61a56d54..310c4c70a 100644
--- a/api-service/session/env.py
+++ b/api-service/session/env.py
@@ -16,3 +16,10 @@ def format_env_vars(envs: List[EnvVar]) -> dict[str, str]:
envs,
{},
)
+
+def cmd_with_env_vars(cmd: str, envs: dict[str, str]):
+ return reduce(
+ lambda acc, env: f"{env[0]}={env[1]} " + acc,
+ envs.items(),
+ cmd,
+ )
diff --git a/api-service/session/playground/base.py b/api-service/session/playground/base.py
index c7d9f9912..46646e748 100644
--- a/api-service/session/playground/base.py
+++ b/api-service/session/playground/base.py
@@ -1,5 +1,6 @@
import time
import math
+from session.env import cmd_with_env_vars
from session.session import GetEnvs, Session
from playground_client.models.create_mock_body_data_request import (
@@ -8,7 +9,6 @@ from playground_client.models.create_mock_body_data_request import (
import playground_client
from playground_client.models.file import File
-
class Playground(Session):
port_check_interval = 0.5 # 500ms
max_port_checks = 10
@@ -42,7 +42,8 @@ class Playground(Session):
response = self.api.start_process(
self.id,
playground_client.StartProcessParams(
- cmd=cmd,
+ cmd=cmd_with_env_vars(cmd, self.env_vars),
+ # TODO: Env vars are not correctly passed to the devbookd process - that's why we add them with cmd_with_env_vars.
envVars=self.env_vars,
rootdir=rootdir,
),
@@ -80,7 +81,8 @@ class Playground(Session):
return self.api.start_process(
self.id,
playground_client.StartProcessParams(
- cmd=cmd,
+ cmd=cmd_with_env_vars(cmd, self.env_vars),
+ # TODO: Env vars are not correctly passed to the devbookd process - that's why we add them with cmd_with_env_vars.
envVars=self.env_vars,
rootdir=rootdir,
),