From 4c262bad94e6fe361bcdebd2710d3722ffeb28a1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 12 Dec 2025 14:31:44 +0000 Subject: [PATCH 1/2] Add waitForExit() method documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Documents the new process.waitForExit() method that allows waiting for process completion and retrieving exit codes. Includes API reference documentation and practical examples in the background processes guide. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/content/docs/sandbox/api/commands.mdx | 41 +++++++++++++++++ .../sandbox/guides/background-processes.mdx | 44 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/src/content/docs/sandbox/api/commands.mdx b/src/content/docs/sandbox/api/commands.mdx index c8aacaea1d39c00..9cb6c4e270c8197 100644 --- a/src/content/docs/sandbox/api/commands.mdx +++ b/src/content/docs/sandbox/api/commands.mdx @@ -106,6 +106,7 @@ const process = await sandbox.startProcess(command: string, options?: ProcessOpt - `getLogs()` - Get accumulated logs - `waitForPort()` - Wait for process to listen on a port - `waitForLog()` - Wait for pattern in process output +- `waitForExit()` - Wait for process to exit ``` @@ -316,6 +317,46 @@ await server.waitForLog('Ready', 30000); - `ProcessReadyTimeoutError` - If pattern is not found within timeout - `ProcessExitedBeforeReadyError` - If process exits before pattern appears +### `process.waitForExit()` + +Wait for a process to exit and retrieve its exit code. + +```ts +const result = await process.waitForExit(timeout?: number): Promise +``` + +**Parameters**: +- `timeout` - Maximum wait time in milliseconds (optional) + +**Returns**: `Promise` with: +- `exitCode` - The process exit code + +Use `getProcessLogs()` or `streamProcessLogs()` to retrieve output after the process exits. + + +``` +const build = await sandbox.startProcess('npm run build'); + +// Wait for build to complete +const result = await build.waitForExit(); + +if (result.exitCode === 0) { + console.log('Build succeeded'); + const logs = await sandbox.getProcessLogs(build.id); + console.log('Output:', logs); +} else { + console.error('Build failed with code:', result.exitCode); +} + +// With timeout +const test = await sandbox.startProcess('npm test'); +const result = await test.waitForExit(60000); // 60 second timeout +``` + + +**Throws**: +- `ProcessReadyTimeoutError` - If process does not exit within timeout + ## Related resources - [Background processes guide](/sandbox/guides/background-processes/) - Managing long-running processes diff --git a/src/content/docs/sandbox/guides/background-processes.mdx b/src/content/docs/sandbox/guides/background-processes.mdx index a523eba829da408..47f1ca057a06db9 100644 --- a/src/content/docs/sandbox/guides/background-processes.mdx +++ b/src/content/docs/sandbox/guides/background-processes.mdx @@ -110,6 +110,49 @@ console.log('Server is ready:', result.line); ``` +## Wait for process completion + +For short-lived processes like builds or tests, wait for the process to exit and check the exit code: + + +``` +const build = await sandbox.startProcess('npm run build'); + +// Wait for build to complete +const result = await build.waitForExit(); + +if (result.exitCode === 0) { + console.log('Build succeeded'); + + // Get the output + const logs = await sandbox.getProcessLogs(build.id); + console.log('Build output:', logs); +} else { + console.error('Build failed with exit code:', result.exitCode); +} +``` + + +With a timeout to prevent waiting indefinitely: + + +``` +const test = await sandbox.startProcess('npm test'); + +try { + // Wait up to 60 seconds for tests to complete + const result = await test.waitForExit(60000); + + console.log('Tests completed with exit code:', result.exitCode); +} catch (error) { + if (error.code === 'PROCESS_READY_TIMEOUT') { + console.error('Tests timed out after 60 seconds'); + await sandbox.killProcess(test.id); + } +} +``` + + ## Monitor process logs Stream logs in real-time: @@ -226,6 +269,7 @@ When using `keepAlive: true`, containers will not automatically timeout. You **m ## Best practices - **Wait for readiness** - Use `waitForPort()` or `waitForLog()` to detect when services are ready +- **Wait for completion** - Use `waitForExit()` for build processes and scripts to check exit codes - **Clean up** - Always stop processes when done - **Handle failures** - Monitor logs for errors and restart if needed - **Use try/finally** - Ensure cleanup happens even on errors From def6ade53447bd5c1ce6427dc01d1e86f3bc6917 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 12 Dec 2025 14:33:07 +0000 Subject: [PATCH 2/2] Add documentation for waitForExit() method Documents the new Process.waitForExit() method that allows waiting for background processes to complete and retrieving their exit codes. Updates: - API reference with method signature, parameters, and examples - Background processes guide with practical usage patterns - Best practices to recommend waitForExit() over arbitrary timeouts --- src/content/docs/sandbox/api/commands.mdx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/content/docs/sandbox/api/commands.mdx b/src/content/docs/sandbox/api/commands.mdx index 9cb6c4e270c8197..867b6c167a4fe78 100644 --- a/src/content/docs/sandbox/api/commands.mdx +++ b/src/content/docs/sandbox/api/commands.mdx @@ -106,7 +106,7 @@ const process = await sandbox.startProcess(command: string, options?: ProcessOpt - `getLogs()` - Get accumulated logs - `waitForPort()` - Wait for process to listen on a port - `waitForLog()` - Wait for pattern in process output -- `waitForExit()` - Wait for process to exit +- `waitForExit()` - Wait for process to exit and get exit code ``` @@ -329,9 +329,7 @@ const result = await process.waitForExit(timeout?: number): Promise` with: -- `exitCode` - The process exit code - -Use `getProcessLogs()` or `streamProcessLogs()` to retrieve output after the process exits. +- `exitCode` - The process exit code (0 for success, non-zero for errors) ``` @@ -342,15 +340,22 @@ const result = await build.waitForExit(); if (result.exitCode === 0) { console.log('Build succeeded'); - const logs = await sandbox.getProcessLogs(build.id); - console.log('Output:', logs); } else { - console.error('Build failed with code:', result.exitCode); + console.error('Build failed with exit code:', result.exitCode); + + // Get logs to see what went wrong + const logs = await build.getLogs(); + console.error('Build logs:', logs); } // With timeout const test = await sandbox.startProcess('npm test'); -const result = await test.waitForExit(60000); // 60 second timeout +try { + const result = await test.waitForExit(60000); // 60 second timeout + console.log('Tests completed with exit code:', result.exitCode); +} catch (error) { + console.error('Tests timed out after 60 seconds'); +} ```