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
@@ -298,42 +351,38 @@ For a fully interactive terminal experience similar to SSH, you need to:
298
351
```js JavaScript & TypeScript
299
352
import { Sandbox } from'@e2b/code-interpreter'
300
353
301
-
asyncfunctionmain() {
302
-
constsandbox=awaitSandbox.create()
354
+
constsandbox=awaitSandbox.create()
303
355
304
-
// Set terminal to raw mode for character-by-character input
305
-
process.stdin.setRawMode(true)
356
+
// Set terminal to raw mode for character-by-character input
357
+
process.stdin.setRawMode(true)
306
358
307
-
constterminal=awaitsandbox.pty.create({
308
-
cols:process.stdout.columns,
309
-
rows:process.stdout.rows,
310
-
onData: (data) =>process.stdout.write(data),
311
-
timeoutMs:0,
312
-
})
359
+
constterminal=awaitsandbox.pty.create({
360
+
cols:process.stdout.columns,
361
+
rows:process.stdout.rows,
362
+
onData: (data) =>process.stdout.write(data),
363
+
timeoutMs:0,
364
+
})
313
365
314
-
// Forward stdin to the PTY
315
-
process.stdin.on('data', async (data) => {
316
-
awaitsandbox.pty.sendInput(terminal.pid, data)
317
-
})
366
+
// Forward stdin to the PTY
367
+
process.stdin.on('data', async (data) => {
368
+
awaitsandbox.pty.sendInput(terminal.pid, data)
369
+
})
318
370
319
-
// Handle terminal resize
320
-
process.stdout.on('resize', () => {
321
-
sandbox.pty.resize(terminal.pid, {
322
-
cols:process.stdout.columns,
323
-
rows:process.stdout.rows,
324
-
})
371
+
// Handle terminal resize
372
+
process.stdout.on('resize', () => {
373
+
sandbox.pty.resize(terminal.pid, {
374
+
cols:process.stdout.columns,
375
+
rows:process.stdout.rows,
325
376
})
377
+
})
326
378
327
-
// Wait for the session to end
328
-
try {
329
-
awaitterminal.wait()
330
-
} finally {
331
-
process.stdin.setRawMode(false)
332
-
awaitsandbox.kill()
333
-
}
379
+
// Wait for the session to end
380
+
try {
381
+
awaitterminal.wait()
382
+
} finally {
383
+
process.stdin.setRawMode(false)
384
+
awaitsandbox.kill()
334
385
}
335
-
336
-
main()
337
386
```
338
387
339
388
```python Python
@@ -355,6 +404,7 @@ async def main():
355
404
# Set terminal to raw mode
356
405
tty.setraw(sys.stdin.fileno())
357
406
407
+
# Write raw bytes directly to stdout (no extra newlines added)
358
408
terminal =await sandbox.pty.create(
359
409
size=PtySize(cols=80, rows=24),
360
410
on_data=lambdadata: sys.stdout.buffer.write(data) or sys.stdout.flush(),
@@ -387,5 +437,5 @@ asyncio.run(main())
387
437
</CodeGroup>
388
438
389
439
<Note>
390
-
This is the same pattern used by the [E2B CLI](https://github.com/e2b-dev/E2B/blob/main/packages/cli/src/terminal.ts) to provide interactive sandbox sessions. For production use, consider batching input to reduce network calls.
440
+
This is the same pattern used by the [E2B CLI](https://github.com/e2b-dev/E2B/blob/main/packages/cli/src/terminal.ts) to provide interactive sandbox sessions. For production use, consider batching input to reduce network lag.
0 commit comments