Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Fix import error; Disable fs and process tools; Cleanup

Tomas Valentac04a75d3e58a
diff --git a/api-service/app.py b/api-service/app.py
index 599414c30..4241439b1 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -6,7 +6,7 @@ from typing import Dict, List
from flask import Flask, abort, request
from flask_cors import CORS
-from codegen.codegen import EnvVar
+from codegen.env import EnvVar
from codegen import generate_req_handler
from database import Database, DeploymentState
diff --git a/api-service/codegen/codegen.py b/api-service/codegen/codegen.py
index a7ce631cd..717e109c3 100644
--- a/api-service/codegen/codegen.py
+++ b/api-service/codegen/codegen.py
@@ -1,8 +1,8 @@
from typing import List, Dict
from langchain.llms.openai import OpenAIChat, OpenAI
-from typing import TypedDict
# from codegen.tools.documentation import ReadDocumentation
+from codegen.env import EnvVar
from codegen.js_agent import create_js_agent
from codegen.prompt import PREFIX, SUFFIX
from codegen.tools.playground import create_playground_tools
@@ -10,11 +10,6 @@ from codegen.tools.javascript import JavascriptEvalTool
from database import Database
-class EnvVar(TypedDict):
- key: str
- value: str
-
-
def generate_req_handler(
db: Database,
run_id: str,
diff --git a/api-service/codegen/env.py b/api-service/codegen/env.py
new file mode 100644
index 000000000..4e712fbac
--- /dev/null
+++ b/api-service/codegen/env.py
@@ -0,0 +1,6 @@
+from typing import TypedDict
+
+
+class EnvVar(TypedDict):
+ key: str
+ value: str
diff --git a/api-service/codegen/tools/javascript/tool.py b/api-service/codegen/tools/javascript/tool.py
index 7b3ade6e1..c7bc92daa 100644
--- a/api-service/codegen/tools/javascript/tool.py
+++ b/api-service/codegen/tools/javascript/tool.py
@@ -16,4 +16,4 @@ class JavascriptEvalTool(BaseTool):
return js_eval(query)
async def _arun(self, query: str) -> str:
- return NotImplementedError("JavascriptEval does not support async")
+ raise NotImplementedError("JavascriptEval does not support async")
diff --git a/api-service/codegen/tools/playground/main.py b/api-service/codegen/tools/playground/main.py
index 5412992a2..a55052d07 100644
--- a/api-service/codegen/tools/playground/main.py
+++ b/api-service/codegen/tools/playground/main.py
@@ -1,6 +1,7 @@
from typing import List, Any
-from codegen.codegen import EnvVar
+from codegen.env import EnvVar
+from codegen.tools.playground.mock.request import MockRequestFactory
from .playground import NodeJSPlayground, Playground
from .tools.filesystem import create_filesystem_tools
from .tools.process import create_process_tools
@@ -11,13 +12,15 @@ from .tools.code import create_code_tools
# TODO: Use ubuntu instead of alpine?
def create_playground_tools(envs: List[EnvVar]) -> tuple[List[Any], Playground]:
playground = NodeJSPlayground(envs)
+ mock = MockRequestFactory()
+
subtools = [
tool
for tools in (
- tool_factory(playground)
+ tool_factory(playground=playground, mock=mock)
for tool_factory in [
# create_filesystem_tools,
- create_process_tools,
+ # create_process_tools,
create_code_tools,
]
)
diff --git a/api-service/codegen/tools/playground/mock/request.py b/api-service/codegen/tools/playground/mock/request.py
new file mode 100644
index 000000000..54a102301
--- /dev/null
+++ b/api-service/codegen/tools/playground/mock/request.py
@@ -0,0 +1,2 @@
+class MockRequestFactory:
+ pass
diff --git a/api-service/codegen/tools/playground/playground.py b/api-service/codegen/tools/playground/playground.py
index cd42de6c0..2d787d721 100644
--- a/api-service/codegen/tools/playground/playground.py
+++ b/api-service/codegen/tools/playground/playground.py
@@ -3,8 +3,8 @@ import time
from functools import reduce
-from typing import Dict, List
-from codegen.codegen import EnvVar
+from typing import List
+from codegen.env import EnvVar
import playground_client
diff --git a/api-service/codegen/tools/playground/tools/code.py b/api-service/codegen/tools/playground/tools/code.py
index 02387f5b1..50dd9c107 100644
--- a/api-service/codegen/tools/playground/tools/code.py
+++ b/api-service/codegen/tools/playground/tools/code.py
@@ -1,5 +1,6 @@
from langchain.agents import tool
+from codegen.tools.playground.mock.request import MockRequestFactory
from codegen.tools.playground.playground import NodeJSPlayground
from codegen.tools.playground.tools.process import encode_command_output
@@ -8,7 +9,7 @@ def extract_code(code: str):
return code.strip().strip("`").strip()
-def create_code_tools(playground: NodeJSPlayground):
+def create_code_tools(playground: NodeJSPlayground, mock: MockRequestFactory):
# Ensure that the function is a generator even if no tools are yielded
yield from ()
@@ -17,7 +18,6 @@ def create_code_tools(playground: NodeJSPlayground):
"""
Install specified dependecies with NPM and return errors.
The input should be a list of Node.js dependencies separated by spaces.
- If you are using this tool to handle missing dependency error try to run the code again after the installation.
"""
output = playground.install_dependencies(extract_code(dependencies))
result = encode_command_output(output, only_errors=True)
@@ -37,7 +37,7 @@ def create_code_tools(playground: NodeJSPlayground):
return result if len(result) > 0 else "Code execution finished without error"
- yield run_typescript_code
+ # yield run_typescript_code
@tool("CheckTypeScriptCodeTypes")
def check_typescript_code_types(code: str) -> str:
@@ -49,12 +49,14 @@ def create_code_tools(playground: NodeJSPlayground):
return result if len(result) > 0 else "Typechecking finished without error"
- yield check_typescript_code_types
+ # yield check_typescript_code_types
+ # This tool is just for executing JavaScript without doing the request to server
@tool("RunJavaScriptCode")
def run_javascript_code(code: str) -> str:
"""
- Run the specified JavaScript code and return errors and output.
+ Run JavaScript code and return errors and output.
+ Input should be a valid JavaScript code.
"""
output = playground.run_javascript_code(extract_code(code))
result = encode_command_output(output)
@@ -62,29 +64,25 @@ def create_code_tools(playground: NodeJSPlayground):
yield run_javascript_code
- @tool("TestJavaScriptServerCode")
- def test_server_code(input: str) -> str:
- """
- Execute JavaScript code that should start a server and then executes a testing command that should test if the server correctly handles needed requests.
- The server should run on http://localhost:3000 and the request should be made on http://localhost:3000 too.
- The testing command should be a `curl` command.
- The input to this tool should be the testing command followed by a newline then the server code wrapped in three backtics.
- The returned result is a the testing command output followed by the server code output and errors.
- """
-
- test_cmd, server_code = input.split("\n", 1)
- code = extract_code(server_code)
+ # @tool("RunJavaScriptCode")
+ # def run_javascript_code(code: str) -> str:
+ # """
+ # Execute JavaScript code that should start a server then tests if server correctly handles needed requests.
+ # The input should be a valid JavaScriptCode.
+ # The server should run on http://localhost:3000.
+ # The returned result is a the testing request output followed by the server code output and errors.
+ # """
- port = 3000
- test_output, server_output = playground.test_javascript_server_code(
- code=code, test_cmd=test_cmd, port=port
- )
+ # mock_request = mock.requestComand()
- test_result = encode_command_output(test_output)
- server_result = encode_command_output(server_output)
+ # port = 3000
+ # test_output, server_output = playground.test_javascript_server_code(
+ # code=code, test_cmd=mock_request.command, port=port
+ # )
- return f"Test command result:\n{test_result}\n\nServer result:\n{server_result}"
+ # test_result = encode_command_output(test_output)
+ # server_result = encode_command_output(server_output)
- # yield test_server_code
+ # return f"Test request result:\n{test_result}\nCode execution result:\n{server_result}"
- # @tool("JavaScriptREPL/Shell")
+ # yield run_javascript_code
diff --git a/api-service/codegen/tools/playground/tools/process.py b/api-service/codegen/tools/playground/tools/process.py
index 1f96a4eef..80ea8a305 100644
--- a/api-service/codegen/tools/playground/tools/process.py
+++ b/api-service/codegen/tools/playground/tools/process.py
@@ -42,4 +42,4 @@ def create_process_tools(playground: NodeJSPlayground):
return result if len(result) > 0 else "Process finished without error"
- # yield run_terminal_command
+ yield run_terminal_command