Skip to content

Commit a061784

Browse files
committed
fix run cmd
1 parent 4936f22 commit a061784

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

openhands/runtime/impl/e2b/e2b_runtime.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
FileWriteObservation,
1515
Observation,
1616
)
17-
from openhands.events.observation.commands import CmdOutputObservation
17+
from openhands.events.observation.commands import CmdOutputMetadata, CmdOutputObservation
1818
from openhands.events.stream import EventStream
1919
from openhands.runtime.base import Runtime
2020
from openhands.runtime.impl.e2b.filestore import E2BFileStore
@@ -105,9 +105,9 @@ def list_files(self, path: str | None = None) -> list[str]:
105105
def run(self, action: CmdRunAction) -> CmdOutputObservation | ErrorObservation:
106106
exit_code, output = self.sandbox.execute(action.command)
107107
if exit_code == 0:
108-
return CmdOutputObservation(output, exit_code, action.command)
108+
return CmdOutputObservation(content=output, command=action.command, metadata=CmdOutputMetadata(exit_code=exit_code))
109109
else:
110110
return ErrorObservation(output)
111111

112112
def run_ipython(self, action: IPythonRunCellAction) -> Observation:
113-
return NotImplementedError
113+
return ErrorObservation("Not implemented yet")

openhands/runtime/impl/e2b/sandbox.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from glob import glob
55

66
from e2b import Sandbox
7-
from e2b.exceptions import TimeoutException
7+
from e2b.sandbox.commands.command_handle import CommandExitException
88

99
from openhands.core.config import SandboxConfig
1010
from openhands.core.logger import openhands_logger as logger
@@ -57,21 +57,14 @@ def _archive(self, host_src: str, recursive: bool = False):
5757

5858
def execute(self, cmd: str, timeout: int | None = None) -> tuple[int, str]:
5959
timeout = timeout if timeout is not None else self.config.timeout
60-
process = self.sandbox.commands._start(cmd, envs=self._env, timeout=timeout)
6160
try:
62-
process_output = process.wait()
63-
except TimeoutException:
64-
logger.debug('Command timed out, killing process...')
65-
process.kill()
66-
return -1, f'Command: "{cmd}" timed out'
67-
68-
logs = [m.line for m in process_output.messages]
69-
logs_str = '\n'.join(logs)
70-
if process.exit_code is None:
71-
return -1, logs_str
72-
73-
assert process_output.exit_code is not None
74-
return process_output.exit_code, logs_str
61+
process = self.sandbox.commands.run(cmd, envs=self._env, timeout=timeout)
62+
output = process.stdout
63+
exit_code = process.exit_code
64+
except CommandExitException as e:
65+
output = e.stdout
66+
exit_code = e.exit_code
67+
return exit_code, output
7568

7669
def copy_to(self, host_src: str, sandbox_dest: str, recursive: bool = False):
7770
"""Copies a local file or directory to the sandbox."""

0 commit comments

Comments
 (0)