Skip to content

Commit 055b341

Browse files
committed
Add timeout and accumulated output documentation
- Document the 60-second default timeout (total session duration) - Show how to disable timeout for long-running sessions - Add note about accumulated stdout while disconnected - Add example for accessing accumulated output after reconnect
1 parent b8c16c4 commit 055b341

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

docs/sandbox/pty.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ asyncio.run(main())
6262
The PTY runs an interactive bash shell with `TERM=xterm-256color`, which supports ANSI colors and escape sequences.
6363
</Note>
6464

65+
## Timeout
66+
67+
By default, PTY sessions have a **60-second timeout** which limits the total duration of the session. When the timeout is reached, the connection will be closed regardless of activity.
68+
69+
For long-running sessions, set `timeoutMs: 0` (JavaScript) or `timeout=0` (Python) to disable the timeout.
70+
71+
<CodeGroup>
72+
```js JavaScript & TypeScript
73+
const terminal = await sandbox.pty.create({
74+
cols: 80,
75+
rows: 24,
76+
onData: (data) => process.stdout.write(data),
77+
timeoutMs: 0, // No timeout for long-running sessions
78+
})
79+
```
80+
81+
```python Python
82+
terminal = await sandbox.pty.create(
83+
size=PtySize(cols=80, rows=24),
84+
on_data=lambda data: print(data.decode(), end=''),
85+
timeout=0, # No timeout for long-running sessions
86+
)
87+
```
88+
</CodeGroup>
89+
6590
## Send input to PTY
6691

6792
Use `sendInput()` in JavaScript or `send_stdin()` in Python to send data to the terminal.
@@ -155,6 +180,10 @@ You can disconnect from a PTY session while keeping it running, then reconnect l
155180
- Sharing terminal access between multiple clients
156181
- Implementing terminal session persistence
157182

183+
<Note>
184+
While disconnected, the PTY continues to accumulate output. You can access all output generated during the session (including while disconnected) via the `stdout` property on the terminal handle.
185+
</Note>
186+
158187
<CodeGroup>
159188
```js JavaScript & TypeScript
160189
import { Sandbox } from '@e2b/code-interpreter'
@@ -227,6 +256,33 @@ asyncio.run(main())
227256
```
228257
</CodeGroup>
229258

259+
### Accessing accumulated output
260+
261+
After reconnecting, you can access all output generated during the session (including while disconnected) via the `stdout` property:
262+
263+
<CodeGroup>
264+
```js JavaScript & TypeScript
265+
// After reconnecting...
266+
const reconnected = await sandbox.pty.connect(pid, {
267+
onData: (data) => { /* handle new data */ },
268+
})
269+
270+
// Access all accumulated output from the session
271+
console.log('All output so far:', reconnected.stdout)
272+
```
273+
274+
```python Python
275+
# After reconnecting...
276+
reconnected = await sandbox.pty.connect(
277+
pid,
278+
on_data=lambda data: print(data.decode(), end=''),
279+
)
280+
281+
# Access all accumulated output from the session
282+
print('All output so far:', reconnected.stdout)
283+
```
284+
</CodeGroup>
285+
230286
## Kill the PTY
231287

232288
Terminate the PTY session with `kill()`.

0 commit comments

Comments
 (0)