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
- 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
Copy file name to clipboardExpand all lines: docs/sandbox/pty.mdx
+56Lines changed: 56 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,31 @@ asyncio.run(main())
62
62
The PTY runs an interactive bash shell with `TERM=xterm-256color`, which supports ANSI colors and escape sequences.
63
63
</Note>
64
64
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
+
constterminal=awaitsandbox.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=lambdadata: print(data.decode(), end=''),
85
+
timeout=0, # No timeout for long-running sessions
86
+
)
87
+
```
88
+
</CodeGroup>
89
+
65
90
## Send input to PTY
66
91
67
92
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
155
180
- Sharing terminal access between multiple clients
156
181
- Implementing terminal session persistence
157
182
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
+
158
187
<CodeGroup>
159
188
```js JavaScript & TypeScript
160
189
import { Sandbox } from'@e2b/code-interpreter'
@@ -227,6 +256,33 @@ asyncio.run(main())
227
256
```
228
257
</CodeGroup>
229
258
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
+
constreconnected=awaitsandbox.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)
0 commit comments