Skip to content

Commit 08b6c59

Browse files
committed
Cross-reference commands & processes better
1 parent cac2af3 commit 08b6c59

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/content/docs/sandbox/api/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { getSandbox } from '@cloudflare/sandbox';
1717
const sandbox = getSandbox(env.Sandbox, 'user-123');
1818
```
1919

20-
The sandbox ID should be unique per user or session. The same ID will always return the same sandbox instance with persistent state.
20+
The same sandbox ID will always return the same sandbox instance. You can architect your application to use a single sandbox ID for multiple users, or use unique IDs per user or session. Using unique sandbox IDs per user is recommended if you are providing code generation or execution capabilities directly to your users.
2121

2222
## API organization
2323

src/content/docs/sandbox/guides/background-processes.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ Use `startProcess()` instead of `exec()` when:
1919
- **Continuous monitoring** - Log watchers, health checkers
2020
- **Parallel execution** - Multiple services running simultaneously
2121

22-
Use `exec()` for:
23-
24-
- **One-time commands** - Installations, builds, data processing
25-
- **Quick scripts** - Simple operations that complete and exit
22+
:::note
23+
For **one-time commands, builds, or scripts that complete and exit**, use `exec()` instead. See the [Execute commands guide](/sandbox/guides/execute-commands/).
24+
:::
2625

2726
## Start a background process
2827

src/content/docs/sandbox/guides/execute-commands.mdx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ This guide shows you how to execute commands in the sandbox, handle output, and
1111

1212
## Choose the right method
1313

14-
The SDK provides two methods for command execution:
14+
The SDK provides multiple approaches for running commands:
1515

16-
- **`exec()`** - Run a command and wait for complete result. Best for most use cases.
16+
- **`exec()`** - Run a command and wait for complete result. Best for one-time commands like builds, installations, and scripts.
1717
- **`execStream()`** - Stream output in real-time. Best for long-running commands where you need immediate feedback.
18+
- **`startProcess()`** - Start a background process. Best for web servers, databases, and services that need to keep running.
19+
20+
:::note
21+
For **web servers, databases, or services that need to keep running**, use `startProcess()` instead. See the [Background processes guide](/sandbox/guides/background-processes/).
22+
:::
1823

1924
## Execute basic commands
2025

@@ -132,6 +137,7 @@ await sandbox.exec('python /workspace/analyze.py data.csv');
132137
- **Check exit codes** - Always verify `result.success` and `result.exitCode`
133138
- **Validate inputs** - Escape or validate user input to prevent injection
134139
- **Use streaming** - For long operations, use `execStream()` for real-time feedback
140+
- **Use background processes** - For services that need to keep running (web servers, databases), use the [Background processes guide](/sandbox/guides/background-processes/) instead
135141
- **Handle errors** - Check stderr for error details
136142

137143
## Troubleshooting

0 commit comments

Comments
 (0)