Skip to content

πŸ™Œ OpenHands: AI-Driven Development

remove sandbox abstract class (#3337)

Yufan Song99ac91f6ad22
diff --git a/opendevin/core/schema/__init__.py b/opendevin/core/schema/__init__.py
index 416aa0736b..2fa4e1aa3e 100644
--- a/opendevin/core/schema/__init__.py
+++ b/opendevin/core/schema/__init__.py
@@ -2,13 +2,10 @@ from .action import ActionType
from .agent import AgentState
from .config import ConfigType
from .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.py
deleted file mode 100644
index 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]:
- pass
diff --git a/opendevin/runtime/__init__.py b/opendevin/runtime/__init__.py
index 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 Sandbox
def get_runtime_cls(name: str):
diff --git a/opendevin/runtime/e2b/runtime.py b/opendevin/runtime/e2b/runtime.py
index 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 Sandbox
from opendevin.runtime.plugins import PluginRequirement
from 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.py
index 361a0df15c..08af9eb02b 100644
--- a/opendevin/runtime/e2b/sandbox.py
+++ b/opendevin/runtime/e2b/sandbox.py
@@ -1,5 +1,6 @@
import os
import tarfile
+import copy
from glob import glob
from e2b import Sandbox as E2BSandbox
@@ -9,13 +10,12 @@ from e2b.sandbox.exception import (
from opendevin.core.config import SandboxConfig
from 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 = True
def __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_plugins
self.sandbox = E2BSandbox(
api_key=e2b_api_key,
template=template,
@@ -62,8 +63,8 @@ class E2BBox(Sandbox):
return tar_filename
def 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.timeout
process = self.sandbox.process.start(cmd, env_vars=self._env)
try:
diff --git a/opendevin/runtime/sandbox.py b/opendevin/runtime/sandbox.py
deleted file mode 100644
index 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