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,165 @@ 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.
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.
115
+
116
+
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:
174
+
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
175
62
176
<CodeGroup>
63
177
64
178
```typescript JavaScript & TypeScript
65
179
import {
66
180
waitForPort,
181
+
waitForURL,
67
182
waitForProcess,
68
183
waitForFile,
69
184
waitForTimeout,
@@ -72,30 +187,38 @@ import {
72
187
// Wait for a port to be available
73
188
waitForPort(3000)
74
189
190
+
// Wait for a URL to return a specific status code (defaults to 200)
191
+
waitForURL('http://localhost:3000/health')
192
+
waitForURL('http://localhost:3000/health', 200)
193
+
75
194
// Wait for a process to be running
76
195
waitForProcess('node')
77
196
78
197
// Wait for a file to exist
79
198
waitForFile('/tmp/ready')
80
199
81
-
// Wait for a timeout
200
+
// Wait for a specified duration (in milliseconds, minimum 1000)
82
201
waitForTimeout(10_000) // 10 seconds
83
202
```
84
203
85
204
```python Python
86
-
from e2b import wait_for_port, wait_for_process, wait_for_file, wait_for_timeout
205
+
from e2b import wait_for_port, wait_for_url, wait_for_process, wait_for_file, wait_for_timeout
87
206
88
207
# Wait for a port to be available
89
208
wait_for_port(3000)
90
209
210
+
# Wait for a URL to return a specific status code (defaults to 200)
211
+
wait_for_url("http://localhost:3000/health")
212
+
wait_for_url("http://localhost:3000/health", 200)
213
+
91
214
# Wait for a process to be running
92
215
wait_for_process("node")
93
216
94
217
# Wait for a file to exist
95
218
wait_for_file("/tmp/ready")
96
219
97
-
# Wait for a specified duration
98
-
wait_for_timeout(10_000) # 10 seconds
220
+
# Wait for a specified duration (in milliseconds, minimum 1000)
0 commit comments