diff --git a/packages/js-sdk/src/sandbox/commands/index.ts b/packages/js-sdk/src/sandbox/commands/index.ts index 61cb9e283c..9e2457c37a 100644 --- a/packages/js-sdk/src/sandbox/commands/index.ts +++ b/packages/js-sdk/src/sandbox/commands/index.ts @@ -393,7 +393,11 @@ export class Commands { cmd: string, opts?: CommandStartOpts & { background?: boolean } ): Promise { - const proc = await this.start(cmd, opts) + const startOpts = + opts?.background && opts?.timeoutMs === undefined + ? { ...opts, timeoutMs: 0 } + : opts + const proc = await this.start(cmd, startOpts) return opts?.background ? proc : proc.wait() } diff --git a/packages/python-sdk/e2b/sandbox_async/commands/command.py b/packages/python-sdk/e2b/sandbox_async/commands/command.py index 32b75fd26b..715c8ae2c4 100644 --- a/packages/python-sdk/e2b/sandbox_async/commands/command.py +++ b/packages/python-sdk/e2b/sandbox_async/commands/command.py @@ -144,7 +144,7 @@ async def run( on_stdout: Optional[OutputHandler[Stdout]] = None, on_stderr: Optional[OutputHandler[Stderr]] = None, stdin: Optional[bool] = None, - timeout: Optional[float] = 60, + timeout: Optional[float] = None, request_timeout: Optional[float] = None, ) -> CommandResult: """ @@ -158,7 +158,7 @@ async def run( :param on_stdout: Callback for command stdout output :param on_stderr: Callback for command stderr output :param stdin: If `True`, the command will have a stdin stream that you can send data to using `sandbox.commands.send_stdin()` - :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time + :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time. Default is `60` seconds for foreground commands, `0` (no limit) for background commands :param request_timeout: Timeout for the request in **seconds** :return: `CommandResult` result of the command execution @@ -176,7 +176,7 @@ async def run( on_stdout: Optional[OutputHandler[Stdout]] = None, on_stderr: Optional[OutputHandler[Stderr]] = None, stdin: Optional[bool] = None, - timeout: Optional[float] = 60, + timeout: Optional[float] = None, request_timeout: Optional[float] = None, ) -> AsyncCommandHandle: """ @@ -190,7 +190,7 @@ async def run( :param on_stdout: Callback for command stdout output :param on_stderr: Callback for command stderr output :param stdin: If `True`, the command will have a stdin stream that you can send data to using `sandbox.commands.send_stdin()` - :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time + :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time. Default is `0` (no limit) for background commands :param request_timeout: Timeout for the request in **seconds** :return: `AsyncCommandHandle` handle to interact with the running command @@ -207,7 +207,7 @@ async def run( on_stdout: Optional[OutputHandler[Stdout]] = None, on_stderr: Optional[OutputHandler[Stderr]] = None, stdin: Optional[bool] = None, - timeout: Optional[float] = 60, + timeout: Optional[float] = None, request_timeout: Optional[float] = None, ): # Check version for stdin support @@ -220,12 +220,20 @@ async def run( # Default to `False` stdin = stdin or False + # When timeout is not explicitly provided, default to 60s for foreground + # commands, or 0 (unlimited) for background commands so the process + # remains reachable for connect(pid) + if timeout is None: + effective_timeout = 0 if background else 60 + else: + effective_timeout = timeout + proc = await self._start( cmd, envs, user, cwd, - timeout, + effective_timeout, request_timeout, stdin, on_stdout=on_stdout, diff --git a/packages/python-sdk/e2b/sandbox_sync/commands/command.py b/packages/python-sdk/e2b/sandbox_sync/commands/command.py index 512b7d9923..bb0c87e44b 100644 --- a/packages/python-sdk/e2b/sandbox_sync/commands/command.py +++ b/packages/python-sdk/e2b/sandbox_sync/commands/command.py @@ -143,7 +143,7 @@ def run( on_stdout: Optional[Callable[[str], None]] = None, on_stderr: Optional[Callable[[str], None]] = None, stdin: Optional[bool] = None, - timeout: Optional[float] = 60, + timeout: Optional[float] = None, request_timeout: Optional[float] = None, ) -> CommandResult: """ @@ -157,7 +157,7 @@ def run( :param on_stdout: Callback for command stdout output :param on_stderr: Callback for command stderr output :param stdin: If `True`, the command will have a stdin stream that you can send data to using `sandbox.commands.send_stdin()` - :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time + :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time. Default is `60` seconds for foreground commands, `0` (no limit) for background commands :param request_timeout: Timeout for the request in **seconds** :return: `CommandResult` result of the command execution @@ -175,7 +175,7 @@ def run( on_stdout: None = None, on_stderr: None = None, stdin: Optional[bool] = None, - timeout: Optional[float] = 60, + timeout: Optional[float] = None, request_timeout: Optional[float] = None, ) -> CommandHandle: """ @@ -187,7 +187,7 @@ def run( :param user: User to run the command as :param cwd: Working directory to run the command :param stdin: If `True`, the command will have a stdin stream that you can send data to using `sandbox.commands.send_stdin()` - :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time + :param timeout: Timeout for the command connection in **seconds**. Using `0` will not limit the command connection time. Default is `0` (no limit) for background commands :param request_timeout: Timeout for the request in **seconds** :return: `CommandHandle` handle to interact with the running command @@ -204,7 +204,7 @@ def run( on_stdout: Optional[Callable[[str], None]] = None, on_stderr: Optional[Callable[[str], None]] = None, stdin: Optional[bool] = None, - timeout: Optional[float] = 60, + timeout: Optional[float] = None, request_timeout: Optional[float] = None, ): # Check version for stdin support @@ -217,13 +217,21 @@ def run( # Default to `False` stdin = stdin or False + # When timeout is not explicitly provided, default to 60s for foreground + # commands, or 0 (unlimited) for background commands so the process + # remains reachable for connect(pid) + if timeout is None: + effective_timeout = 0 if background else 60 + else: + effective_timeout = timeout + proc = self._start( cmd, envs, user, cwd, stdin, - timeout, + effective_timeout, request_timeout, )