Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add timeout for wait

Jakub Novakb62502fba243
diff --git a/.changeset/sweet-dolls-smile.md b/.changeset/sweet-dolls-smile.md
new file mode 100644
index 000000000..bc1f8c54b
--- /dev/null
+++ b/.changeset/sweet-dolls-smile.md
@@ -0,0 +1,6 @@
+---
+"@e2b/python-sdk": patch
+"@e2b/sdk": patch
+---
+
+Add timeout for wait command
diff --git a/packages/js-sdk/src/sandbox/process.ts b/packages/js-sdk/src/sandbox/process.ts
index 7e9aa955e..4de41032c 100644
--- a/packages/js-sdk/src/sandbox/process.ts
+++ b/packages/js-sdk/src/sandbox/process.ts
@@ -1,5 +1,6 @@
import { EnvVars } from './envVars'
import { CallOpts, SandboxConnection } from './sandboxConnection'
+import { withTimeout } from '../utils/promise'
export const processService = 'process'
@@ -128,9 +129,11 @@ export class Process {
/**
* Waits for the process to finish.
+ *
+ * @param timeout Timeout for the process to finish in milliseconds
*/
- async wait(): Promise<ProcessOutput> {
- return this.finished
+ async wait(timeout?: number): Promise<ProcessOutput> {
+ return await withTimeout(() => this.finished, timeout)()
}
/**
diff --git a/packages/python-sdk/e2b/sandbox/process.py b/packages/python-sdk/e2b/sandbox/process.py
index af6856cc5..62ff4140c 100644
--- a/packages/python-sdk/e2b/sandbox/process.py
+++ b/packages/python-sdk/e2b/sandbox/process.py
@@ -165,11 +165,13 @@ class Process:
"""
return self._process_id
- def wait(self):
+ def wait(self, timeout: Optional[float] = None) -> ProcessOutput:
"""
Wait for the process to exit.
+
+ :param timeout: Specify the duration, in seconds to give the method to finish its execution before it times out. If set to None, the method will continue to wait until it completes, regardless of time
"""
- return self._finished.result()
+ return self._finished.result(timeout)
def send_stdin(self, data: str, timeout: Optional[float] = TIMEOUT) -> None:
"""