|
4 | 4 | from glob import glob |
5 | 5 |
|
6 | 6 | from e2b import Sandbox |
7 | | -from e2b.exceptions import TimeoutException |
| 7 | +from e2b.sandbox.commands.command_handle import CommandExitException |
8 | 8 |
|
9 | 9 | from openhands.core.config import SandboxConfig |
10 | 10 | from openhands.core.logger import openhands_logger as logger |
@@ -57,21 +57,14 @@ def _archive(self, host_src: str, recursive: bool = False): |
57 | 57 |
|
58 | 58 | def execute(self, cmd: str, timeout: int | None = None) -> tuple[int, str]: |
59 | 59 | timeout = timeout if timeout is not None else self.config.timeout |
60 | | - process = self.sandbox.commands._start(cmd, envs=self._env, timeout=timeout) |
61 | 60 | 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 |
75 | 68 |
|
76 | 69 | def copy_to(self, host_src: str, sandbox_dest: str, recursive: bool = False): |
77 | 70 | """Copies a local file or directory to the sandbox.""" |
|
0 commit comments