Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Fix sandbox ID in JS SDK list method

Tomas Valentae07b0786381e
diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.ts
index db28f2795..597b2b568 100644
--- a/packages/js-sdk/src/index.ts
+++ b/packages/js-sdk/src/index.ts
@@ -27,7 +27,7 @@ export { DataAnalysis as CodeInterpreter }
export { Artifact, DataAnalysis } from './templates/dataAnalysis'
export type { RunPythonOpts } from './templates/dataAnalysis'
-export type { SandboxMetadata } from './sandbox/sandboxConnection'
+export type { SandboxMetadata, RunningSandbox } from './sandbox/sandboxConnection'
export type { Action } from './sandbox/index'
export { Sandbox }
diff --git a/packages/js-sdk/src/sandbox/sandboxConnection.ts b/packages/js-sdk/src/sandbox/sandboxConnection.ts
index a4aee6dfc..de8715e61 100644
--- a/packages/js-sdk/src/sandbox/sandboxConnection.ts
+++ b/packages/js-sdk/src/sandbox/sandboxConnection.ts
@@ -42,6 +42,7 @@ export interface RunningSandbox {
templateID: string;
alias?: string;
metadata?: SandboxMetadata;
+ startedAt: Date;
}
export interface SandboxConnectionOpts {
@@ -150,12 +151,23 @@ export class SandboxConnection {
/**
* List all running sandboxes
+ *
* @param apiKey API key to use for authentication. If not provided, the `E2B_API_KEY` environment variable will be used.
*/
static async list(apiKey?: string): Promise<RunningSandbox[]> {
apiKey = getApiKey(apiKey)
+
try {
- return (await listSandboxes(apiKey, {})).data
+ const res = await listSandboxes(apiKey, {})
+
+ return res.data.map(sandbox => ({
+ sandboxID: `${sandbox.sandboxID}-${sandbox.clientID}`,
+ templateID: sandbox.templateID,
+ alias: sandbox.alias,
+ ...sandbox.metadata && { metadata: sandbox.metadata },
+ startedAt: new Date(sandbox.startedAt),
+ }))
+
} catch (e) {
if (e instanceof listSandboxes.Error) {
const error = e.getActualType()