@@ -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 properties and methods:
100+ - ` id ` - Unique process identifier
101+ - ` pid ` - System process ID
102+ - ` command ` - Command that was executed
103+ - ` status ` - Current process status
104+ - ` kill(signal?: string) ` - Terminate the process
105+ - ` getStatus() ` - Get current process status
106+ - ` getLogs() ` - Get accumulated logs
107+ - ` waitForLog(pattern, timeout?) ` - Wait for log pattern (see [ process.waitForLog()] ( #processwaitforlog ) )
108+ - ` waitForPort(port, options?) ` - Wait for port readiness (see [ process.waitForPort()] ( #processwaitforport ) )
100109
101110<TypeScriptExample >
102111```
@@ -213,6 +222,95 @@ console.log('Server logs:', logs);
213222```
214223</TypeScriptExample >
215224
225+ ### ` process.waitForLog() `
226+
227+ Wait for a log pattern to appear in process output. This method checks existing logs first, then streams new output until the pattern is found.
228+
229+ ``` ts
230+ const result = await process .waitForLog (pattern : string | RegExp , timeout ?: number ): Promise < WaitForLogResult >
231+ ```
232+
233+ ** Parameters** :
234+ - ` pattern ` - String to search for or RegExp pattern to match
235+ - ` timeout ` (optional) - Maximum time to wait in milliseconds (no timeout by default)
236+
237+ ** Returns** : ` Promise<WaitForLogResult> ` with:
238+ - ` line ` - The log line that matched the pattern
239+ - ` match ` (optional) - RegExp capture groups if pattern was a RegExp
240+
241+ ** Errors** :
242+ - ` ProcessReadyTimeoutError ` - Pattern not found within timeout period
243+ - ` ProcessExitedBeforeReadyError ` - Process exited before pattern appeared
244+
245+ <TypeScriptExample >
246+ ```
247+ // Wait for simple string pattern
248+ const server = await sandbox.startProcess('python -m http.server 8000');
249+ await server.waitForLog('Serving HTTP');
250+ console.log('Server is ready');
251+
252+ // Wait with timeout
253+ const app = await sandbox.startProcess('npm run dev');
254+ await app.waitForLog('Local: http://localhost:3000', 30000); // 30s timeout
255+
256+ // Use RegExp for pattern matching
257+ const build = await sandbox.startProcess('npm run build');
258+ const result = await build.waitForLog(/Built in (\d+)ms/);
259+ console.log('Matched line:', result.line);
260+ console.log('Build time:', result.match?.[1]);
261+ ```
262+ </TypeScriptExample >
263+
264+ ### ` process.waitForPort() `
265+
266+ Wait for a process to start listening on a port. Supports both HTTP health checks and TCP connection checks.
267+
268+ ``` ts
269+ await process .waitForPort (port : number , options ?: WaitForPortOptions ): Promise < void >
270+ ```
271+
272+ ** Parameters** :
273+ - ` port ` - Port number to check
274+ - ` options ` (optional):
275+ - ` mode ` - Check mode: ` 'http' ` (default) or ` 'tcp' `
276+ - ` path ` - HTTP path to check (default: ` '/' ` , only for HTTP mode)
277+ - ` status ` - Expected HTTP status code or range (default: ` { min: 200, max: 399 } ` )
278+ - Single number: exact match (e.g., ` 200 ` )
279+ - Object with min/max: range match (e.g., ` { min: 200, max: 299 } ` )
280+ - ` timeout ` - Maximum time to wait in milliseconds (no timeout by default)
281+ - ` interval ` - Interval between checks in milliseconds (default: ` 500 ` )
282+
283+ ** Errors** :
284+ - ` ProcessReadyTimeoutError ` - Port not ready within timeout period
285+ - ` ProcessExitedBeforeReadyError ` - Process exited before port became ready
286+
287+ <TypeScriptExample >
288+ ```
289+ // Wait for HTTP endpoint with default settings (200-399 status on /)
290+ const web = await sandbox.startProcess('npm run dev');
291+ await web.waitForPort(3000);
292+ console.log('Web server ready at http://localhost:3000');
293+
294+ // Check specific health endpoint
295+ const api = await sandbox.startProcess('node api.js');
296+ await api.waitForPort(8080, {
297+ path: '/health',
298+ status: 200,
299+ timeout: 30000 // 30 second timeout
300+ });
301+
302+ // TCP-only check (just verify port accepts connections)
303+ const db = await sandbox.startProcess('redis-server');
304+ await db.waitForPort(6379, { mode: 'tcp' });
305+
306+ // Wait for specific status code range
307+ const app = await sandbox.startProcess('python app.py');
308+ await app.waitForPort(5000, {
309+ status: { min: 200, max: 299 } // Only 2xx status codes
310+ });
311+ ```
312+ </TypeScriptExample >
313+
216314## Related resources
217315
218316- [ Background processes guide] ( /sandbox/guides/background-processes/ ) - Managing long-running processes
0 commit comments