Skip to content

Commit 13e418a

Browse files
authored
Merge branch 'main' into add-app-preview-example
2 parents 4fab1f9 + 7c299e9 commit 13e418a

1 file changed

Lines changed: 55 additions & 2 deletions

File tree

docs/sandbox/auto-resume.mdx

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const sandbox = await Sandbox.create({
1818
timeoutMs: 10 * 60 * 1000,
1919
lifecycle: {
2020
onTimeout: 'pause',
21-
autoResume: true, // resume when traffic arrives
21+
autoResume: true, // resume when activity arrives
2222
},
2323
})
2424
```
@@ -29,7 +29,7 @@ sandbox = Sandbox.create(
2929
timeout=10 * 60,
3030
lifecycle={
3131
"on_timeout": "pause",
32-
"auto_resume": True, # resume when traffic arrives
32+
"auto_resume": True, # resume when activity arrives
3333
},
3434
)
3535
```
@@ -54,6 +54,59 @@ sandbox = Sandbox.create(
5454

5555
If you use `autoResume: false`, resume explicitly with [`Sandbox.connect()`](/docs/sandbox/connect).
5656

57+
## What counts as activity
58+
59+
Auto-resume is triggered by the sandbox activity - that's both HTTP traffic and controlling the sandbox from the SDK.
60+
61+
That includes SDK operations like:
62+
- `sandbox.commands.run(...)`
63+
- `sandbox.files.read(...)`
64+
- `sandbox.files.write(...)`
65+
- opening a tunneled app URL or sending requests to a service running inside the sandbox
66+
67+
If a sandbox is paused and `autoResume` is enabled, the next supported operation resumes it automatically. You do not need to call [`Sandbox.connect()`](/docs/sandbox/connect) first.
68+
69+
### SDK example: pause, then read a file
70+
71+
<CodeGroup>
72+
```js JavaScript & TypeScript
73+
import { Sandbox } from 'e2b'
74+
75+
const sandbox = await Sandbox.create({
76+
timeoutMs: 10 * 60 * 1000,
77+
lifecycle: {
78+
onTimeout: 'pause',
79+
autoResume: true,
80+
},
81+
})
82+
83+
await sandbox.files.write('/home/user/hello.txt', 'hello from a paused sandbox')
84+
await sandbox.pause()
85+
86+
const content = await sandbox.files.read('/home/user/hello.txt')
87+
console.log(content)
88+
console.log(`State after read: ${(await sandbox.getInfo()).state}`)
89+
```
90+
```python Python
91+
from e2b import Sandbox
92+
93+
sandbox = Sandbox.create(
94+
timeout=10 * 60,
95+
lifecycle={
96+
"on_timeout": "pause",
97+
"auto_resume": True,
98+
},
99+
)
100+
101+
sandbox.files.write("/home/user/hello.txt", "hello from a paused sandbox")
102+
sandbox.pause()
103+
104+
content = sandbox.files.read("/home/user/hello.txt")
105+
print(content)
106+
print(f"State after read: {sandbox.get_info().state}")
107+
```
108+
</CodeGroup>
109+
57110
## Use cases
58111

59112
### Web and dev/preview servers

0 commit comments

Comments
 (0)