Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add run javascript timeout

Tomas Valenta6d5d90a03e7d
diff --git a/api-service/codegen/tools/playground/playground.py b/api-service/codegen/tools/playground/playground.py
index 8eb75868e..d52d27bda 100644
--- a/api-service/codegen/tools/playground/playground.py
+++ b/api-service/codegen/tools/playground/playground.py
@@ -158,6 +158,8 @@ class NodeJSPlayground(Playground):
node_js_env_id = "dCeMnVVxu01L"
rootdir = "/code"
+ run_code_timeout = 5 # 5s
+
default_javascript_code_file = os.path.join(rootdir, "index.js")
default_typescript_code_file = os.path.join(rootdir, "index.ts")
@@ -165,16 +167,22 @@ class NodeJSPlayground(Playground):
super().__init__(NodeJSPlayground.node_js_env_id)
self.env_vars = self.format_env_vars(envs)
- def run_javascript_code(self, code: str):
+ def run_javascript_code(self, code: str, timeout: float = run_code_timeout):
print(f"Running javascript code: {code}")
self.write_file(self.default_javascript_code_file, code)
- res = self.run_command(
+
+ process_id = self.start_process(
f"node {self.default_javascript_code_file}",
rootdir=self.rootdir,
env_vars=self.env_vars,
)
- print(res)
- return res
+
+ # For now we always wait the full timeout interval
+ time.sleep(timeout)
+
+ result = self.stop_process(process_id)
+ print(result)
+ return result
def run_typescript_code(self, code: str, typecheck: bool = False):
self.write_file(self.default_typescript_code_file, code)
diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.py
index 691a6688c..370c357b9 100644
--- a/api-service/codegen/tools/playground/tools/code.py
+++ b/api-service/codegen/tools/playground/tools/code.py
@@ -122,7 +122,7 @@ def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory):
f"Curl result:\n{request_result}\nCode execution result:\n{server_result}"
)
- yield curl_javascript_server
+ # yield curl_javascript_server
# @tool("RunJavaScriptCode")
# def run_javascript_code(code: str) -> str: