Skip to content

🙌 OpenHands: AI-Driven Development

refactored timeout (#2044)

மனோஜ்குமார் பழனிச்சாமிcfae6821fae4
diff --git a/opendevin/runtime/docker/exec_box.py b/opendevin/runtime/docker/exec_box.py
index 6af621d251..ab279c5dc0 100644
--- a/opendevin/runtime/docker/exec_box.py
+++ b/opendevin/runtime/docker/exec_box.py
@@ -107,7 +107,7 @@ class DockerExecBox(Sandbox):
def __init__(
self,
container_image: str | None = None,
- timeout: int = 120,
+ timeout: int = config.sandbox_timeout,
sid: str | None = None,
):
# Initialize docker client. Throws an exception if Docker is not reachable.
diff --git a/opendevin/runtime/docker/local_box.py b/opendevin/runtime/docker/local_box.py
index 6214e264cd..81c4f138e4 100644
--- a/opendevin/runtime/docker/local_box.py
+++ b/opendevin/runtime/docker/local_box.py
@@ -26,7 +26,7 @@ from opendevin.runtime.sandbox import Sandbox
class LocalBox(Sandbox):
- def __init__(self, timeout: int = 120):
+ def __init__(self, timeout: int = config.sandbox_timeout):
os.makedirs(config.workspace_base, exist_ok=True)
self.timeout = timeout
self.background_commands: dict[int, Process] = {}
diff --git a/opendevin/runtime/docker/ssh_box.py b/opendevin/runtime/docker/ssh_box.py
index 72ef51321c..491b3bf784 100644
--- a/opendevin/runtime/docker/ssh_box.py
+++ b/opendevin/runtime/docker/ssh_box.py
@@ -199,7 +199,7 @@ class DockerSSHBox(Sandbox):
def __init__(
self,
container_image: str | None = None,
- timeout: int = 120,
+ timeout: int = config.sandbox_timeout,
sid: str | None = None,
):
logger.info(
@@ -219,10 +219,6 @@ class DockerSSHBox(Sandbox):
sid + str(uuid.uuid4()) if sid is not None else str(uuid.uuid4())
)
- # TODO: this timeout is actually essential - need a better way to set it
- # if it is too short, the container may still waiting for previous
- # command to finish (e.g. apt-get update)
- # if it is too long, the user may have to wait for a unnecessary long time
self.timeout = timeout
self.container_image = (
config.sandbox_container_image
@@ -432,7 +428,7 @@ class DockerSSHBox(Sandbox):
def execute(
self, cmd: str, stream: bool = False, timeout: int | None = None
) -> tuple[int, str | CancellableStream]:
- timeout = timeout if timeout is not None else self.timeout
+ timeout = timeout or self.timeout
commands = split_bash_commands(cmd)
if len(commands) > 1:
all_output = ''
diff --git a/opendevin/runtime/e2b/sandbox.py b/opendevin/runtime/e2b/sandbox.py
index cca9171f94..a4225a2643 100644
--- a/opendevin/runtime/e2b/sandbox.py
+++ b/opendevin/runtime/e2b/sandbox.py
@@ -24,7 +24,7 @@ class E2BBox(Sandbox):
def __init__(
self,
template: str = 'open-devin',
- timeout: int = 120,
+ timeout: int = config.sandbox_timeout,
):
self.sandbox = E2BSandbox(
api_key=config.e2b_api_key,
diff --git a/opendevin/runtime/runtime.py b/opendevin/runtime/runtime.py
index 5d96655abe..a6d94eef5d 100644
--- a/opendevin/runtime/runtime.py
+++ b/opendevin/runtime/runtime.py
@@ -36,13 +36,13 @@ from opendevin.storage import FileStore, InMemoryFileStore
def create_sandbox(sid: str = 'default', sandbox_type: str = 'exec') -> Sandbox:
if sandbox_type == 'exec':
- return DockerExecBox(sid=sid, timeout=config.sandbox_timeout)
+ return DockerExecBox(sid=sid)
elif sandbox_type == 'local':
- return LocalBox(timeout=config.sandbox_timeout)
+ return LocalBox()
elif sandbox_type == 'ssh':
- return DockerSSHBox(sid=sid, timeout=config.sandbox_timeout)
+ return DockerSSHBox(sid=sid)
elif sandbox_type == 'e2b':
- return E2BBox(timeout=config.sandbox_timeout)
+ return E2BBox()
else:
raise ValueError(f'Invalid sandbox type: {sandbox_type}')