You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,7 +4,8 @@ description: "Define running processes for the sandbox"
4
4
---
5
5
6
6
## Start command
7
-
The start command lets you specify a process that runs at the **end of the template build** — not when a sandbox is created.
7
+
8
+
The start command specifies a process that runs at the **end of the template build** — not when a sandbox is created.
8
9
During the build, E2B executes the start command, waits for the [ready command](#ready-command) to confirm the process is up, and then takes a [snapshot](/docs/template/how-it-works) of the entire sandbox including the running process.
9
10
10
11
When you later create a sandbox from that template, the snapshotted process is **already running** — there is no startup wait.
@@ -19,51 +20,159 @@ This is how you get servers, seeded databases, or any long-running process avail
19
20
You can see the full build process [here](/docs/template/how-it-works).
20
21
21
22
## Ready command
22
-
The ready command allows you to specify a command that will determine **template sandbox** readiness before a [snapshot](/docs/template/how-it-works) is created.
23
+
24
+
The ready command determines when the sandbox is ready before a [snapshot](/docs/template/how-it-works) is created.
23
25
It is executed in an infinite loop until it returns a successful **exit code 0**.
24
-
This way you can control how long should we wait for the [start command](/docs/template/start-ready-command#start-command) or any system state.
26
+
This lets you control how long the build waits for the [start command](#start-command) or any other system state to be ready.
25
27
26
-
## Usage
28
+
## `setStartCmd` / `set_start_cmd`
27
29
28
-
Set the start command (executed during template build) and the ready command (determines when the process is up before snapshotting):
30
+
Use `setStartCmd` / `set_start_cmd` when you want to run a process during the template build**and** wait for it to be ready. This method accepts **two arguments**: the start command and the ready command.
The ready command is used to determine when the sandbox is ready to accept connections.
106
+
## `setReadyCmd` / `set_ready_cmd`
107
+
108
+
Use `setReadyCmd` / `set_ready_cmd` when you **don't need a start command** but still want to control when the sandbox snapshot is taken. This method accepts only **one argument**: the ready command.
109
+
110
+
This is useful when your template's build steps (e.g., `runCmd` / `run_cmd`) already start a background process or when you just need extra time for the system to settle before snapshotting.
The SDK provides helper functions for common ready command patterns:
168
+
The SDK provides helper functions for common ready command patterns. These can be used with both `setStartCmd` / `set_start_cmd` and `setReadyCmd` / `set_ready_cmd`.
61
169
62
170
<CodeGroup>
63
171
64
172
```typescript JavaScript & TypeScript
65
173
import {
66
174
waitForPort,
175
+
waitForURL,
67
176
waitForProcess,
68
177
waitForFile,
69
178
waitForTimeout,
@@ -72,30 +181,38 @@ import {
72
181
// Wait for a port to be available
73
182
waitForPort(3000)
74
183
184
+
// Wait for a URL to return a specific status code (defaults to 200)
185
+
waitForURL('http://localhost:3000/health')
186
+
waitForURL('http://localhost:3000/health', 200)
187
+
75
188
// Wait for a process to be running
76
189
waitForProcess('node')
77
190
78
191
// Wait for a file to exist
79
192
waitForFile('/tmp/ready')
80
193
81
-
// Wait for a timeout
194
+
// Wait for a specified duration
82
195
waitForTimeout(10_000) // 10 seconds
83
196
```
84
197
85
198
```python Python
86
-
from e2b import wait_for_port, wait_for_process, wait_for_file, wait_for_timeout
199
+
from e2b import wait_for_port, wait_for_url, wait_for_process, wait_for_file, wait_for_timeout
87
200
88
201
# Wait for a port to be available
89
202
wait_for_port(3000)
90
203
204
+
# Wait for a URL to return a specific status code (defaults to 200)
0 commit comments