Skip to content

Commit a870286

Browse files
committed
Use timeout instead of explicit sbx.kill() in template examples
Replace explicit sandbox cleanup with timeout parameter across all template example pages. This simplifies the usage examples while ensuring sandboxes are automatically terminated after 60 seconds.
1 parent 7bff328 commit a870286

6 files changed

Lines changed: 12 additions & 46 deletions

File tree

docs/template/examples/claude-code.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ Start a sandbox with your API key and run prompts.
7575
<CodeGroup>
7676

7777
```typescript JavaScript & TypeScript
78-
// sandbox.ts
7978
import { Sandbox } from 'e2b'
8079

8180
const sbx = await Sandbox.create('claude-code', {
81+
timeoutMs: 60_000,
8282
envs: {
8383
ANTHROPIC_API_KEY: '<your api key>',
8484
},
@@ -89,16 +89,14 @@ const result = await sbx.commands.run(
8989
{ timeoutMs: 0 }
9090
)
9191
console.log(result.stdout)
92-
93-
await sbx.kill()
9492
```
9593

9694
```python Python
97-
# sandbox.py
9895
from e2b import Sandbox
9996

10097
sbx = Sandbox(
10198
'claude-code',
99+
timeout=60,
102100
envs={
103101
'ANTHROPIC_API_KEY': '<your api key>',
104102
},
@@ -109,8 +107,6 @@ result = sbx.commands.run(
109107
timeout=0,
110108
)
111109
print(result.stdout)
112-
113-
sbx.kill()
114110
```
115111

116112
</CodeGroup>

docs/template/examples/desktop.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,27 +186,21 @@ Start a sandbox and open the desktop in your browser.
186186
<CodeGroup>
187187

188188
```typescript JavaScript & TypeScript
189-
// sandbox.ts
190189
import { Sandbox } from 'e2b'
191190

192-
const sbx = await Sandbox.create('desktop')
191+
const sbx = await Sandbox.create('desktop', { timeoutMs: 60_000 })
193192

194193
const url = sbx.getHost(6080)
195194
console.log('Desktop available at:', url)
196-
197-
await sbx.kill()
198195
```
199196

200197
```python Python
201-
# sandbox.py
202198
from e2b import Sandbox
203199

204-
sbx = Sandbox('desktop')
200+
sbx = Sandbox('desktop', timeout=60)
205201

206202
url = sbx.get_host(6080)
207203
print('Desktop available at:', url)
208-
209-
sbx.kill()
210204
```
211205

212206
</CodeGroup>

docs/template/examples/docker.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,20 @@ Start a sandbox and run containers.
6969

7070
<CodeGroup>
7171
```typescript JavaScript & TypeScript
72-
// sandbox.ts
7372
import { Sandbox } from 'e2b'
7473

75-
const sbx = await Sandbox.create('e2b-docker-template')
74+
const sbx = await Sandbox.create('e2b-docker-template', { timeoutMs: 60_000 })
7675

7776
const result = await sbx.commands.run('sudo docker run --rm alpine echo "Hello from Alpine!"')
7877
console.log(result.stdout)
79-
80-
await sbx.kill()
8178
```
8279

8380
```python Python
84-
# sandbox.py
8581
from e2b import Sandbox
8682

87-
sbx = Sandbox('e2b-docker-template')
83+
sbx = Sandbox('e2b-docker-template', timeout=60)
8884

8985
result = sbx.commands.run('sudo docker run --rm alpine echo "Hello from Alpine!"')
9086
print(result.stdout)
91-
92-
sbx.kill()
9387
```
9488
</CodeGroup>

docs/template/examples/expo.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,20 @@ Start a sandbox and get the URL where your Expo app is running.
7575

7676
<CodeGroup>
7777
```typescript JavaScript & TypeScript
78-
// sandbox.ts
7978
import { Sandbox } from 'e2b'
8079

81-
const sbx = await Sandbox.create('expo-app')
80+
const sbx = await Sandbox.create('expo-app', { timeoutMs: 60_000 })
8281

8382
const url = sbx.getHost(8081)
8483
console.log('Expo app running at:', url)
85-
86-
await sbx.kill()
8784
```
8885

8986
```python Python
90-
# sandbox.py
9187
from e2b import Sandbox
9288

93-
sbx = Sandbox('expo-app')
89+
sbx = Sandbox('expo-app', timeout=60)
9490

9591
url = sbx.get_host(8081)
9692
print('Expo app running at:', url)
97-
98-
sbx.kill()
9993
```
10094
</CodeGroup>

docs/template/examples/nextjs-bun.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,20 @@ Start a sandbox and get the URL where your app is running.
8383

8484
<CodeGroup>
8585
```typescript JavaScript & TypeScript
86-
// sandbox.ts
8786
import { Sandbox } from 'e2b'
8887

89-
const sbx = await Sandbox.create('nextjs-app-bun')
88+
const sbx = await Sandbox.create('nextjs-app-bun', { timeoutMs: 60_000 })
9089

9190
const url = sbx.getHost(3000)
9291
console.log('Next.js app running at:', url)
93-
94-
await sbx.kill()
9592
```
9693

9794
```python Python
98-
# sandbox.py
9995
from e2b import Sandbox
10096

101-
sbx = Sandbox('nextjs-app-bun')
97+
sbx = Sandbox('nextjs-app-bun', timeout=60)
10298

10399
url = sbx.get_host(3000)
104100
print('Next.js app running at:', url)
105-
106-
sbx.kill()
107101
```
108102
</CodeGroup>

docs/template/examples/nextjs.mdx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,20 @@ Start a sandbox and get the URL where your app is running.
8585

8686
<CodeGroup>
8787
```typescript JavaScript & TypeScript
88-
// sandbox.ts
8988
import { Sandbox } from 'e2b'
9089

91-
const sbx = await Sandbox.create('nextjs-app')
90+
const sbx = await Sandbox.create('nextjs-app', { timeoutMs: 60_000 })
9291

9392
const url = sbx.getHost(3000)
9493
console.log('Next.js app running at:', url)
95-
96-
await sbx.kill()
9794
```
9895

9996
```python Python
100-
# sandbox.py
10197
from e2b import Sandbox
10298

103-
sbx = Sandbox('nextjs-app')
99+
sbx = Sandbox('nextjs-app', timeout=60)
104100

105101
url = sbx.get_host(3000)
106102
print('Next.js app running at:', url)
107-
108-
sbx.kill()
109103
```
110104
</CodeGroup>

0 commit comments

Comments
 (0)