Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Make terminal work
Jakub Novak4800e760e260
diff --git a/packages/cli/src/commands/sandbox/connect.ts b/packages/cli/src/commands/sandbox/connect.tsindex da4c5b5c5..9a0df248e 100644--- a/packages/cli/src/commands/sandbox/connect.ts+++ b/packages/cli/src/commands/sandbox/connect.ts@@ -34,20 +34,16 @@ export const connectCommand = new commander.Command('connect')async function connectToSandbox({ apiKey, sandboxID }: { apiKey: string, sandboxID: string }) {const sandbox = await Sandbox.connect(sandboxID, { apiKey })- const { exited } = await spawnConnectedTerminal(- sandbox,- `Terminal connected to sandbox ${asPrimary(- sandboxID,- )}\nwith sandbox ID ${asBold(`${sandbox.sandboxId}`)}`,- `Disconnecting terminal from sandbox ${asPrimary(- sandboxID,- )}`,- )-- await exited- console.log(- `Closing terminal connection to sandbox ${asPrimary(- sandboxID,- )}`,- )+ const { exited } = await spawnConnectedTerminal(+ sandbox,+ `Terminal connected to sandbox ${asPrimary(+ sandboxID,+ )} with sandbox ID ${asBold(`${sandbox.sandboxId}`)}`,+ `Disconnecting terminal from sandbox ${asPrimary(+ sandboxID,+ )}`,+ )++ await exited+ console.log(`Closing terminal connection to sandbox ${asPrimary(sandboxID)}`)}diff --git a/packages/cli/src/commands/sandbox/spawn.ts b/packages/cli/src/commands/sandbox/spawn.tsindex 172f6ac7b..327c39204 100644--- a/packages/cli/src/commands/sandbox/spawn.ts+++ b/packages/cli/src/commands/sandbox/spawn.ts@@ -80,15 +80,13 @@ export async function connectSandbox({apiKey: stringtemplate: Pick<e2b.components['schemas']['Template'], 'templateID'>}) {- const sandbox = await e2b.Sandbox.create(template.templateID, {- apiKey,- })+ const sandbox = await e2b.Sandbox.create(template.templateID, { apiKey })const { exited } = await spawnConnectedTerminal(sandbox,`Terminal connected to sandbox ${asFormattedSandboxTemplate(template,- )}\nwith sandbox ID ${asBold(+ )} with sandbox ID ${asBold(`${sandbox.sandboxId}`,)}`,`Disconnecting terminal from sandbox ${asFormattedSandboxTemplate(@@ -96,10 +94,6 @@ export async function connectSandbox({)}`,)- await exited- console.log(- `Closing terminal connection to sandbox ${asFormattedSandboxTemplate(- template,- )}`,- )+ await exited()+ console.log(`Closing terminal connection to sandbox ${asFormattedSandboxTemplate(template)}`)}diff --git a/packages/cli/src/terminal.ts b/packages/cli/src/terminal.tsindex 494ff5312..6709d09a5 100644--- a/packages/cli/src/terminal.ts+++ b/packages/cli/src/terminal.ts@@ -1,4 +1,5 @@import * as e2b from 'e2b'+import {wait} from './utils/wait'function getStdoutSize() {@@ -19,25 +20,20 @@ export async function spawnConnectedTerminal(console.log(introText)const terminalSession = await sandbox.pty.create({- onData: (data: Uint8Array) => {- process.stdout.write(data)- },+ onData: (data: Uint8Array) => process.stdout.write(data),...getStdoutSize()})- process.stdin.setEncoding('utf8')+ // TODO: missing newlinesprocess.stdin.setRawMode(true)-process.stdout.setEncoding('utf8')- const resizeListener = process.stdout.on('resize', () =>- sandbox.pty.resize(terminalSession.pid, getStdoutSize()),- )-- const input = await sandbox.pty.streamInput(terminalSession.pid)- const stdinListener = process.stdin.on('data', (data) => input.sendData(data))+ const resizeListener = process.stdout.on('resize', () => sandbox.pty.resize(terminalSession.pid, getStdoutSize()))+ const stdinListener = process.stdin.on('data', async (data) => await sandbox.pty.sendInput(terminalSession.pid, data))const exited = async () => {+ // TODO: handle exit+ await wait(1000_000)await terminalSession.wait()await input.stop()console.log(exitText)