bashkit 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -53,16 +53,22 @@ var anthropicPromptCacheMiddleware = {
53
53
  import { Sandbox as E2BSandboxSDK } from "@e2b/code-interpreter";
54
54
  function createE2BSandbox(config = {}) {
55
55
  let sandbox = null;
56
+ let sandboxId = config.sandboxId;
56
57
  const workingDirectory = config.cwd || "/home/user";
57
58
  const timeout = config.timeout ?? 300000;
58
59
  const ensureSandbox = async () => {
59
60
  if (sandbox)
60
61
  return sandbox;
61
- sandbox = await E2BSandboxSDK.create({
62
- apiKey: config.apiKey,
63
- timeoutMs: timeout,
64
- metadata: config.metadata
65
- });
62
+ if (config.sandboxId) {
63
+ sandbox = await E2BSandboxSDK.connect(config.sandboxId);
64
+ } else {
65
+ sandbox = await E2BSandboxSDK.create({
66
+ apiKey: config.apiKey,
67
+ timeoutMs: timeout,
68
+ metadata: config.metadata
69
+ });
70
+ sandboxId = sandbox.sandboxId;
71
+ }
66
72
  return sandbox;
67
73
  };
68
74
  const exec = async (command, options) => {
@@ -108,6 +114,9 @@ function createE2BSandbox(config = {}) {
108
114
  };
109
115
  return {
110
116
  exec,
117
+ get id() {
118
+ return sandboxId;
119
+ },
111
120
  async readFile(path) {
112
121
  const result = await exec(`cat "${path}"`);
113
122
  if (result.exitCode !== 0) {
@@ -227,6 +236,7 @@ function createLocalSandbox(config = {}) {
227
236
  import { Sandbox as VercelSandboxSDK } from "@vercel/sandbox";
228
237
  function createVercelSandbox(config = {}) {
229
238
  let sandbox = null;
239
+ let sandboxId = config.sandboxId;
230
240
  const workingDirectory = config.cwd || "/vercel/sandbox";
231
241
  const resolvedConfig = {
232
242
  runtime: config.runtime ?? "node22",
@@ -247,7 +257,12 @@ function createVercelSandbox(config = {}) {
247
257
  token: config.token
248
258
  });
249
259
  }
250
- sandbox = await VercelSandboxSDK.create(createOptions);
260
+ if (config.sandboxId) {
261
+ sandbox = await VercelSandboxSDK.get({ sandboxId: config.sandboxId });
262
+ } else {
263
+ sandbox = await VercelSandboxSDK.create(createOptions);
264
+ }
265
+ sandboxId = sandbox.sandboxId;
251
266
  return sandbox;
252
267
  };
253
268
  const exec = async (command, options) => {
@@ -301,6 +316,9 @@ function createVercelSandbox(config = {}) {
301
316
  };
302
317
  return {
303
318
  exec,
319
+ get id() {
320
+ return sandboxId;
321
+ },
304
322
  async readFile(path) {
305
323
  const sbx = await ensureSandbox();
306
324
  const stream = await sbx.readFile({ path });
@@ -1,6 +1,8 @@
1
1
  import type { Sandbox } from "./interface";
2
2
  export interface E2BSandboxConfig {
3
3
  apiKey?: string;
4
+ /** Existing sandbox ID to reconnect to instead of creating new */
5
+ sandboxId?: string;
4
6
  template?: string;
5
7
  timeout?: number;
6
8
  cwd?: string;
@@ -18,4 +18,11 @@ export interface Sandbox {
18
18
  fileExists(path: string): Promise<boolean>;
19
19
  isDirectory(path: string): Promise<boolean>;
20
20
  destroy(): Promise<void>;
21
+ /**
22
+ * Sandbox ID for reconnection (cloud providers only).
23
+ * - For new sandboxes: available after first operation
24
+ * - For reconnected sandboxes: available immediately
25
+ * - For local sandboxes: always undefined
26
+ */
27
+ readonly id?: string;
21
28
  }
@@ -4,6 +4,8 @@ export interface VercelSandboxConfig {
4
4
  resources?: {
5
5
  vcpus: number;
6
6
  };
7
+ /** Existing sandbox ID to reconnect to instead of creating new */
8
+ sandboxId?: string;
7
9
  timeout?: number;
8
10
  cwd?: string;
9
11
  teamId?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bashkit",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Agentic coding tools for the Vercel AI SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",