@@ -87,7 +87,7 @@ for await (const event of parseSSEStream<ExecEvent>(stream)) {
8787Start a long-running background process.
8888
8989``` ts
90- const process = await sandbox .startProcess (command : string , options ?: ProcessOptions ): Promise < ProcessInfo >
90+ const process = await sandbox .startProcess (command : string , options ?: ProcessOptions ): Promise < Process >
9191```
9292
9393** Parameters** :
@@ -96,7 +96,16 @@ const process = await sandbox.startProcess(command: string, options?: ProcessOpt
9696 - ` cwd ` - Working directory
9797 - ` env ` - Environment variables
9898
99- ** Returns** : ` Promise<ProcessInfo> ` with ` id ` , ` pid ` , ` command ` , ` status `
99+ ** Returns** : ` Promise<Process> ` object with:
100+ - ` id ` - Unique process identifier
101+ - ` pid ` - System process ID
102+ - ` command ` - The command being executed
103+ - ` status ` - Current status (` 'running' ` , ` 'exited' ` , etc.)
104+ - ` kill() ` - Stop the process
105+ - ` getStatus() ` - Get current status
106+ - ` getLogs() ` - Get accumulated logs
107+ - ` waitForPort() ` - Wait for process to listen on a port
108+ - ` waitForLog() ` - Wait for pattern in process output
100109
101110<TypeScriptExample >
102111```
@@ -213,6 +222,100 @@ console.log('Server logs:', logs);
213222```
214223</TypeScriptExample >
215224
225+ ## Process readiness methods
226+
227+ The ` Process ` object returned by ` startProcess() ` includes methods to wait for the process to be ready before proceeding.
228+
229+ ### ` process.waitForPort() `
230+
231+ Wait for a process to listen on a port.
232+
233+ ``` ts
234+ await process .waitForPort (port : number , options ?: WaitForPortOptions ): Promise < void >
235+ ```
236+
237+ ** Parameters** :
238+ - ` port ` - The port number to check
239+ - ` options ` (optional):
240+ - ` mode ` - Check mode: ` 'http' ` (default) or ` 'tcp' `
241+ - ` timeout ` - Maximum wait time in milliseconds
242+ - ` interval ` - Check interval in milliseconds (default: ` 100 ` )
243+ - ` path ` - HTTP path to check (default: ` '/' ` , HTTP mode only)
244+ - ` status ` - Expected HTTP status range (default: ` { min: 200, max: 399 } ` , HTTP mode only)
245+
246+ ** HTTP mode** (default) makes an HTTP GET request and checks the response status:
247+
248+ <TypeScriptExample >
249+ ```
250+ const server = await sandbox.startProcess('node server.js');
251+
252+ // Wait for server to be ready (HTTP mode)
253+ await server.waitForPort(3000);
254+
255+ // Check specific endpoint and status
256+ await server.waitForPort(8080, {
257+ path: '/health',
258+ status: { min: 200, max: 299 },
259+ timeout: 30000
260+ });
261+ ```
262+ </TypeScriptExample >
263+
264+ ** TCP mode** checks if the port accepts connections:
265+
266+ <TypeScriptExample >
267+ ```
268+ const db = await sandbox.startProcess('redis-server');
269+
270+ // Wait for database to accept connections
271+ await db.waitForPort(6379, {
272+ mode: 'tcp',
273+ timeout: 10000
274+ });
275+ ```
276+ </TypeScriptExample >
277+
278+ ** Throws** :
279+ - ` ProcessReadyTimeoutError ` - If port does not become ready within timeout
280+ - ` ProcessExitedBeforeReadyError ` - If process exits before becoming ready
281+
282+ ### ` process.waitForLog() `
283+
284+ Wait for a pattern to appear in process output.
285+
286+ ``` ts
287+ const result = await process .waitForLog (pattern : string | RegExp , timeout ?: number ): Promise < WaitForLogResult >
288+ ```
289+
290+ ** Parameters** :
291+ - ` pattern ` - String or RegExp to match in stdout/stderr
292+ - ` timeout ` - Maximum wait time in milliseconds (optional)
293+
294+ ** Returns** : ` Promise<WaitForLogResult> ` with:
295+ - ` line ` - The matching line of output
296+ - ` matches ` - Array of capture groups (for RegExp patterns)
297+
298+ <TypeScriptExample >
299+ ```
300+ const server = await sandbox.startProcess('node server.js');
301+
302+ // Wait for string pattern
303+ const result = await server.waitForLog('Server listening');
304+ console.log('Ready:', result.line);
305+
306+ // Wait for RegExp with capture groups
307+ const result = await server.waitForLog(/Server listening on port (\d+)/);
308+ console.log('Port:', result.matches[1]); // Extracted port number
309+
310+ // With timeout
311+ await server.waitForLog('Ready', 30000);
312+ ```
313+ </TypeScriptExample >
314+
315+ ** Throws** :
316+ - ` ProcessReadyTimeoutError ` - If pattern is not found within timeout
317+ - ` ProcessExitedBeforeReadyError ` - If process exits before pattern appears
318+
216319## Related resources
217320
218321- [ Background processes guide] ( /sandbox/guides/background-processes/ ) - Managing long-running processes
0 commit comments