π OpenHands: AI-Driven Development
remove sandbox abstract class (#3337)
Yufan Song99ac91f6ad22
diff --git a/opendevin/core/schema/__init__.py b/opendevin/core/schema/__init__.pyindex 416aa0736b..2fa4e1aa3e 100644--- a/opendevin/core/schema/__init__.py+++ b/opendevin/core/schema/__init__.py@@ -2,13 +2,10 @@ from .action import ActionTypefrom .agent import AgentStatefrom .config import ConfigTypefrom .observation import ObservationType-from .stream import CancellableStream, StreamMixin__all__ = ['ActionType','ObservationType','ConfigType','AgentState',- 'CancellableStream',- 'StreamMixin',]diff --git a/opendevin/core/schema/stream.py b/opendevin/core/schema/stream.pydeleted file mode 100644index 29c9c7e463..0000000000--- a/opendevin/core/schema/stream.py+++ /dev/null@@ -1,27 +0,0 @@-from abc import ABC, abstractmethod-from typing import Union---class StreamMixin:- def __init__(self, generator):- self.generator = generator- self.closed = False-- def __iter__(self):- return self-- def __next__(self):- if self.closed:- raise StopIteration- else:- return next(self.generator)---class CancellableStream(StreamMixin, ABC):- @abstractmethod- def close(self):- pass-- @abstractmethod- def exit_code(self) -> Union[int, None]:- passdiff --git a/opendevin/runtime/__init__.py b/opendevin/runtime/__init__.pyindex 26d690826f..ea17ebb442 100644--- a/opendevin/runtime/__init__.py+++ b/opendevin/runtime/__init__.py@@ -1,5 +1,4 @@from .e2b.sandbox import E2BBox-from .sandbox import Sandboxdef get_runtime_cls(name: str):diff --git a/opendevin/runtime/e2b/runtime.py b/opendevin/runtime/e2b/runtime.pyindex 5d90408b55..0a185d5c97 100644--- a/opendevin/runtime/e2b/runtime.py+++ b/opendevin/runtime/e2b/runtime.py@@ -10,7 +10,6 @@ from opendevin.events.observation import (Observation,)from opendevin.events.stream import EventStream-from opendevin.runtime import Sandboxfrom opendevin.runtime.plugins import PluginRequirementfrom opendevin.runtime.runtime import Runtime@@ -26,7 +25,7 @@ class E2BRuntime(Runtime):event_stream: EventStream,sid: str = 'default',plugins: list[PluginRequirement] | None = None,- sandbox: Sandbox | None = None,+ sandbox: E2BSandbox | None = None,):super().__init__(config, event_stream, sid, plugins)if sandbox is None:diff --git a/opendevin/runtime/e2b/sandbox.py b/opendevin/runtime/e2b/sandbox.pyindex 361a0df15c..08af9eb02b 100644--- a/opendevin/runtime/e2b/sandbox.py+++ b/opendevin/runtime/e2b/sandbox.py@@ -1,5 +1,6 @@import osimport tarfile+import copyfrom glob import globfrom e2b import Sandbox as E2BSandbox@@ -9,13 +10,12 @@ from e2b.sandbox.exception import (from opendevin.core.config import SandboxConfigfrom opendevin.core.logger import opendevin_logger as logger-from opendevin.core.schema import CancellableStream-from opendevin.runtime.sandbox import Sandbox--class E2BBox(Sandbox):+class E2BBox:closed = False_cwd: str = '/home/user'+ _env: dict[str, str] = {}+ is_initial_session: bool = Truedef __init__(self,@@ -23,7 +23,8 @@ class E2BBox(Sandbox):e2b_api_key: str,template: str = 'open-devin',):- super().__init__(config)+ self.config = copy.deepcopy(config)+ self.initialize_plugins: bool = config.initialize_pluginsself.sandbox = E2BSandbox(api_key=e2b_api_key,template=template,@@ -62,8 +63,8 @@ class E2BBox(Sandbox):return tar_filenamedef execute(- self, cmd: str, stream: bool = False, timeout: int | None = None- ) -> tuple[int, str | CancellableStream]:+ self, cmd: str, timeout: int | None = None+ ) -> tuple[int, str]:timeout = timeout if timeout is not None else self.config.timeoutprocess = self.sandbox.process.start(cmd, env_vars=self._env)try:diff --git a/opendevin/runtime/sandbox.py b/opendevin/runtime/sandbox.pydeleted file mode 100644index c8ebd87d37..0000000000--- a/opendevin/runtime/sandbox.py+++ /dev/null@@ -1,32 +0,0 @@-import copy-from abc import ABC, abstractmethod--from opendevin.core.config import SandboxConfig-from opendevin.core.schema import CancellableStream---class Sandbox(ABC):- _env: dict[str, str] = {}- is_initial_session: bool = True-- def __init__(self, config: SandboxConfig):- self.config = copy.deepcopy(config)- self.initialize_plugins: bool = config.initialize_plugins-- @abstractmethod- def execute(- self, cmd: str, stream: bool = False, timeout: int | None = None- ) -> tuple[int, str | CancellableStream]:- pass-- @abstractmethod- def close(self):- pass-- @abstractmethod- def copy_to(self, host_src: str, sandbox_dest: str, recursive: bool = False):- pass-- @abstractmethod- def get_working_directory(self):- pass