remove sandbox abstract class (#3337)

* remove sandbox abstract class

* remove cancellable stream
This commit is contained in:
Yufan Song 2024-08-11 07:47:28 -07:00 committed by GitHub
parent 9757f362bf
commit 99ac91f6ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 72 deletions

View File

@ -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',
]

View File

@ -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

View File

@ -1,5 +1,4 @@
from .e2b.sandbox import E2BBox
from .sandbox import Sandbox
def get_runtime_cls(name: str):

View File

@ -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:

View File

@ -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:

View File

@ -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