Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add basic logs command
Tomas Valentae24a4949696a
diff --git a/packages/cli/src/commands/sandbox/index.ts b/packages/cli/src/commands/sandbox/index.tsindex 228ea3cf5..aa2e20b5e 100644--- a/packages/cli/src/commands/sandbox/index.ts+++ b/packages/cli/src/commands/sandbox/index.ts@@ -4,6 +4,7 @@ import { connectCommand } from './connect'import { listCommand } from './list'import { killCommand } from './kill'import { spawnCommand } from './spawn'+import { logsCommand } from './logs'export const sandboxCommand = new commander.Command('sandbox').description('work with sandboxes').alias('sbx')@@ -11,3 +12,4 @@ export const sandboxCommand = new commander.Command('sandbox').description('work.addCommand(listCommand).addCommand(killCommand).addCommand(spawnCommand)+ .addCommand(logsCommand)diff --git a/packages/cli/src/commands/sandbox/logs.ts b/packages/cli/src/commands/sandbox/logs.tsnew file mode 100644index 000000000..7fd46221c--- /dev/null+++ b/packages/cli/src/commands/sandbox/logs.ts@@ -0,0 +1,42 @@+import * as commander from 'commander'+import * as e2b from 'e2b'++import { ensureAPIKey } from 'src/api'+import { asBold } from 'src/utils/format'++const getSandboxLogs = e2b.withAPIKey(+ e2b.api.path('/sandboxes/{sandboxID}/logs').method('get').create(),+)++export const logsCommand = new commander.Command('logs')+ .description('show logs for running sandbox')+ .argument('<sandboxID>', `show longs for sandbox specified by ${asBold('<sandboxID>')}`)+ .alias('lg')+ .action(async (sandboxID: string) => {+ try {+ const apiKey = ensureAPIKey()++ let offset = 0+ // eslint-disable-next-line no-constant-condition+ while (true) {+ const logs = await listSandboxLogs({ apiKey, sandboxID, offset })+ offset = logs.logsOffset++ for (const log of logs.logs) {+ process.stdout.write(`${log}\n`)+ }+ }+ } catch (err: any) {+ console.error(err)+ process.exit(1)+ }+ })++export async function listSandboxLogs({+ apiKey,+ sandboxID,+ offset,+}: { apiKey: string, sandboxID: string, offset: number }): Promise<e2b.components['schemas']['SandboxLogs']> {+ const response = await getSandboxLogs(apiKey, { sandboxID, logsOffset: offset })+ return response.data+}diff --git a/packages/js-sdk/src/api/schema.gen.ts b/packages/js-sdk/src/api/schema.gen.tsindex 3e0870df1..2ba3871af 100644--- a/packages/js-sdk/src/api/schema.gen.ts+++ b/packages/js-sdk/src/api/schema.gen.ts@@ -49,6 +49,31 @@ export interface paths {};};};+ "/sandboxes/{sandboxID}/logs": {+ /** Get sandbox logs */+ get: {+ parameters: {+ path: {+ sandboxID: components["parameters"]["sandboxID"];+ };+ query: {+ /** Index of the starting log that should be returned with the sandbox */+ logsOffset?: number;+ };+ };+ responses: {+ /** Successfully returned the sandbox logs */+ 200: {+ content: {+ "application/json": components["schemas"]["SandboxLogs"];+ };+ };+ 401: components["responses"]["401"];+ 404: components["responses"]["404"];+ 500: components["responses"]["500"];+ };+ };+ };"/sandboxes/{sandboxID}": {/** Kill a sandbox */delete: {@@ -236,6 +261,12 @@ export interface paths {export interface components {schemas: {SandboxMetadata: { [key: string]: string };+ SandboxLogs: {+ /** @description Logs of the sandbox */+ logs: string[];+ /** @description Index of the last log */+ logsOffset: number;+ };Sandbox: {/** @description Identifier of the template from which is the sandbox created */templateID: string;diff --git a/spec/openapi.yml b/spec/openapi.ymlindex 66e01a5f8..65fb0d922 100644--- a/spec/openapi.yml+++ b/spec/openapi.yml@@ -70,6 +70,16 @@ components:type: stringdescription: Metadata of the sandbox+ SandboxLogs:+ required:+ - logs+ properties:+ logs:+ type: array+ items:+ type: string+ description: Logs of the sandbox+Sandbox:required:- templateID@@ -167,23 +177,23 @@ components:required:- dockerfileproperties:- alias:- description: Alias of the template- type: string- dockerfile:- description: Dockerfile for the template- type: string- startCmd:- description: Start command to execute in the template after the build- type: string- cpuCount:- description: CPU cores for the template- type: integer- minimum: 1- memoryMB:- description: Memory limit for the template in MB- type: integer- minimum: 128+ alias:+ description: Alias of the template+ type: string+ dockerfile:+ description: Dockerfile for the template+ type: string+ startCmd:+ description: Start command to execute in the template after the build+ type: string+ cpuCount:+ description: CPU cores for the template+ type: integer+ minimum: 1+ memoryMB:+ description: Memory limit for the template in MB+ type: integer+ minimum: 128TemplateBuild:required:@@ -286,6 +296,40 @@ paths:500:$ref: "#/components/responses/500"+ /sandboxes/{sandboxID}/logs:+ get:+ description: Get sandbox logs+ tags: [sandboxes]+ security:+ - ApiKeyAuth: []+ parameters:+ - $ref: "#/components/parameters/sandboxID"+ - in: query+ name: since+ schema:+ default: 0+ type: integer+ description: Starting timestamp of the logs that should be returned+ - in: query+ name: limit+ schema:+ default: 1000+ type: integer+ description: Maximum number of logs that should be returned+ responses:+ 200:+ description: Successfully returned the sandbox logs+ content:+ application/json:+ schema:+ $ref: "#/components/schemas/SandboxLogs"+ 404:+ $ref: "#/components/responses/404"+ 401:+ $ref: "#/components/responses/401"+ 500:+ $ref: "#/components/responses/500"+/sandboxes/{sandboxID}:delete:description: Kill a sandbox@@ -422,7 +466,7 @@ paths:description: Start the buildtags: [templates]security:- - AccessTokenAuth: []+ - AccessTokenAuth: []parameters:- $ref: "#/components/parameters/templateID"- $ref: "#/components/parameters/buildID"@@ -469,9 +513,9 @@ paths:/templates/{templateID}/builds/{buildID}/status:get:description: Get template build info- tags: [ templates ]+ tags: [templates]security:- - AccessTokenAuth: [ ]+ - AccessTokenAuth: []parameters:- $ref: "#/components/parameters/templateID"- $ref: "#/components/parameters/buildID"