@alineo-labs/sandbox 0.2.0 → 0.3.0

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.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { BashSession, CheckpointInfo, CommandError, DiagnosticEvent, DiagnosticLog, EnvironmentRecord, EnvironmentRecord as EnvironmentRecord$1, EnvironmentRecord as EnvironmentRecord$2, ExecCodeOptions, ExecConnectionError, ExecHandle, ExecOptions, ExecResult, FileInfo, IStorageAdapter, IStorageAdapter as IStorageAdapter$1, InteractiveExecHandle, LedgerEntry, LedgerEvent, ListSandboxOptions, ListSandboxOptions as ListSandboxOptions$1, Metrics, PendingInteractiveExec, SandboxDetails, SandboxDetails as SandboxDetails$1, SandboxError, SandboxHandle, SandboxHandle as SandboxHandle$1, SandboxHooks, SandboxStatus, StepTimeoutError } from "@alineo-labs/core";
2
- import { CodeLanguage } from "@alineo-labs/opensandbox";
1
+ import { BashSession, CheckpointInfo, CommandError, CredentialBinding, CredentialBroker, CredentialBroker as CredentialBroker$1, CredentialResolver, DiagnosticEvent, DiagnosticLog, EnvironmentRecord, EnvironmentRecord as EnvironmentRecord$1, EnvironmentRecord as EnvironmentRecord$2, ExecCodeOptions, ExecConnectionError, ExecHandle, ExecOptions, ExecResult, FileInfo, IStorageAdapter, IStorageAdapter as IStorageAdapter$1, InteractiveExecHandle, LedgerEntry, LedgerEvent, ListSandboxOptions, ListSandboxOptions as ListSandboxOptions$1, Metrics, PendingInteractiveExec, SandboxDetails, SandboxDetails as SandboxDetails$1, SandboxError, SandboxHandle, SandboxHandle as SandboxHandle$1, SandboxHooks, SandboxStatus, StepTimeoutError } from "@alineo-labs/core";
2
+ import { CodeLanguage, CredentialProxyConfig, NetworkPolicy, NetworkPolicy as NetworkPolicy$1, NetworkRule } from "@alineo-labs/opensandbox";
3
+ import { OpenSandboxCredentialBroker } from "@alineo-labs/vault";
3
4
 
4
5
  //#region src/types.d.ts
5
6
  /**
@@ -39,11 +40,30 @@ interface SandboxClientOptions {
39
40
  * in Docker (e.g. started via `alineo init`). Defaults to `false`.
40
41
  */
41
42
  useServerProxy?: boolean;
43
+ /**
44
+ * Broker for `sb.credentials.*` — registers credentials with, and resolves endpoints
45
+ * against, whatever backend actually injects them. Defaults to
46
+ * `OpenSandboxCredentialBroker` (from `@alineo-labs/vault`), wired to this client's own
47
+ * `ControlClient`/`useServerProxy`, if omitted. Only relevant for sandboxes created with
48
+ * `credentialProxy: true`.
49
+ */
50
+ credentialBroker?: CredentialBroker$1;
42
51
  }
43
52
  /** Options for `Sandbox.resume()`. */
44
53
  interface ResumeOptions {
45
54
  /** Resume from the checkpoint with this tag. Defaults to the most recent checkpoint. */
46
55
  tag?: string;
56
+ /**
57
+ * Resolves values for credentials bound via `sb.credentials.set()` on the original sandbox
58
+ * whose `CredentialSource` isn't `"env"` (or whose env var has since become unset) — the
59
+ * vault's own state doesn't survive a resume (it's sidecar-runtime-only), so anything
60
+ * previously bound needs a value from somewhere. `"env"`-sourced credentials resolve
61
+ * automatically without this. Only relevant if the original sandbox had any
62
+ * `sb.credentials.set()` calls; a no-op otherwise. `resume()` throws `SandboxError` if a
63
+ * bound credential can't be resolved (no matching env var, and no callback or one that
64
+ * returns `undefined`) rather than silently omitting it.
65
+ */
66
+ resolveCredential?: CredentialResolver;
47
67
  }
48
68
  /** Options for `Sandbox.sandbox()`. */
49
69
  interface SandboxOptions {
@@ -82,6 +102,21 @@ interface SandboxOptions {
82
102
  * same host script for one logical run).
83
103
  */
84
104
  runId?: string;
105
+ /**
106
+ * Durable resource identity this session's memory should be scoped by — see
107
+ * `@alineo-labs/memory`'s `ResourceRef.resourceId`. Unset by default (unlike `runId`, which
108
+ * always gets a generated fallback) — most sandboxes aren't tied to a memory resource.
109
+ * Threaded through the ledger's `sandbox_created` payload the same way `runId` is, and
110
+ * inherited by `resume()`/`fork()`/`restoreSnapshot()` the same way `runId` is.
111
+ */
112
+ resourceId?: string;
113
+ /**
114
+ * Durable team identity this session's memory should be scoped by — see
115
+ * `@alineo-labs/memory`'s `ResourceRef.teamId`. Unset by default, same as `resourceId`.
116
+ * Threaded through the ledger's `sandbox_created` payload the same way `resourceId` is, and
117
+ * inherited by `resume()`/`fork()`/`restoreSnapshot()` the same way.
118
+ */
119
+ teamId?: string;
85
120
  /** SandboxHandle lifetime in seconds. Defaults to the OpenSandbox server default. */
86
121
  timeout?: number;
87
122
  /** Observability hooks (e.g. `otelHooks(tracer)` from `@alineo-labs/otel`). */
@@ -101,6 +136,18 @@ interface SandboxOptions {
101
136
  * to start the Jupyter kernel service that `execCode()` depends on.
102
137
  */
103
138
  entrypoint?: string[];
139
+ /**
140
+ * Outbound network policy, enforced by an egress sidecar attached to this sandbox. Requires
141
+ * the OpenSandbox server to have `egress.image` configured (`alineo init` does this by
142
+ * default). Omit for unrestricted egress and no sidecar at all — the default, unchanged
143
+ * behavior.
144
+ */
145
+ networkPolicy?: NetworkPolicy$1;
146
+ /**
147
+ * Opts this sandbox into transparent credential injection via `sb.credentials.*`. Requires
148
+ * `networkPolicy` to also be set and the server to be running `egress.mode = "dns+nft"`.
149
+ */
150
+ credentialProxy?: boolean;
104
151
  }
105
152
  //#endregion
106
153
  //#region src/environment.d.ts
@@ -146,6 +193,15 @@ interface EnvironmentSandboxOptions {
146
193
  * Falls back to `EnvironmentOptions.shell`, then `"/bin/sh"`.
147
194
  */
148
195
  shell?: string;
196
+ /**
197
+ * Resource scope for this spawned sandbox — see `SandboxOptions.resourceId`. Unlike
198
+ * `sandbox()`/`resume()`/`restoreSnapshot()`, a sandbox spawned from an environment has no
199
+ * prior ledger session of its own to inherit from, so this must be passed explicitly here.
200
+ */
201
+ resourceId?: string;
202
+ /** Team scope for this spawned sandbox — see `SandboxOptions.teamId`. Same rationale as
203
+ * `resourceId` above. */
204
+ teamId?: string;
149
205
  }
150
206
  /**
151
207
  * A named, reusable sandbox environment.
@@ -225,6 +281,7 @@ declare class Environment {
225
281
  declare class Sandbox {
226
282
  private readonly _control;
227
283
  private readonly _adapter;
284
+ private readonly _credentialBroker;
228
285
  private readonly _maxConcurrency;
229
286
  private readonly _useServerProxy;
230
287
  private _activeCount;
@@ -313,6 +370,13 @@ declare class Sandbox {
313
370
  gpu?: string;
314
371
  };
315
372
  runId?: string;
373
+ /** Default resource scope for any later `.fork()` call — see `SandboxOptions.resourceId`.
374
+ * Same rationale as `opts.runId`: `connect()` does no ledger lookup, so it can't
375
+ * discover the sandbox's original `resourceId` on its own. */
376
+ resourceId?: string;
377
+ /** Default team scope for any later `.fork()` call — see `SandboxOptions.teamId`. Same
378
+ * rationale as `opts.resourceId`. */
379
+ teamId?: string;
316
380
  }): Promise<SandboxHandle$1>;
317
381
  /**
318
382
  * Create a fresh sandbox from a snapshot ID without exec replay.
@@ -342,7 +406,17 @@ declare class Sandbox {
342
406
  cpu: string;
343
407
  memory: string;
344
408
  gpu?: string;
345
- }, runId?: string): Promise<SandboxHandle$1>;
409
+ }, runId?: string, opts?: {
410
+ networkPolicy?: NetworkPolicy$1;
411
+ credentialProxy?: boolean;
412
+ /** Resource scope for the restored sandbox — see `SandboxOptions.resourceId`. Unlike
413
+ * `resume()`, `restoreSnapshot()` has no prior ledger session of its own to inherit
414
+ * from (the snapshot may have come from anywhere), so this must be passed explicitly. */
415
+ resourceId?: string;
416
+ /** Team scope for the restored sandbox — see `SandboxOptions.teamId`. Same rationale as
417
+ * `resourceId` above. */
418
+ teamId?: string;
419
+ }): Promise<SandboxHandle$1>;
346
420
  /**
347
421
  * SandboxHandle history management. List, inspect, and delete past sandbox records.
348
422
  *
@@ -415,4 +489,4 @@ declare class Sandbox {
415
489
  private _releaseSlot;
416
490
  }
417
491
  //#endregion
418
- export { BashSession, type CheckpointInfo, CodeLanguage, CommandError, type DiagnosticEvent, type DiagnosticLog, Environment, type EnvironmentOptions, type EnvironmentRecord, type EnvironmentSandboxOptions, type ExecCodeOptions, ExecConnectionError, type ExecHandle, type ExecOptions, type ExecResult, type FileInfo, type IStorageAdapter, type InteractiveExecHandle, type LedgerEntry, LedgerEvent, type ListSandboxOptions, type Metrics, type PendingInteractiveExec, type ResumeOptions, Sandbox, SandboxClientError, type SandboxClientOptions, type SandboxDetails, SandboxError, SandboxHandle, type SandboxOptions, SandboxStatus, StepTimeoutError };
492
+ export { BashSession, type CheckpointInfo, CodeLanguage, CommandError, type CredentialBinding, type CredentialBroker, type CredentialProxyConfig, type DiagnosticEvent, type DiagnosticLog, Environment, type EnvironmentOptions, type EnvironmentRecord, type EnvironmentSandboxOptions, type ExecCodeOptions, ExecConnectionError, type ExecHandle, type ExecOptions, type ExecResult, type FileInfo, type IStorageAdapter, type InteractiveExecHandle, type LedgerEntry, LedgerEvent, type ListSandboxOptions, type Metrics, type NetworkPolicy, type NetworkRule, OpenSandboxCredentialBroker, type PendingInteractiveExec, type ResumeOptions, Sandbox, SandboxClientError, type SandboxClientOptions, type SandboxDetails, SandboxError, SandboxHandle, type SandboxOptions, SandboxStatus, StepTimeoutError };
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { BashSession, CommandError, ExecConnectionError, LedgerEvent, LedgerEvent as LedgerEvent$1, SandboxError, SandboxHandle, SandboxHandle as SandboxHandle$1, SandboxStatus, StepTimeoutError } from "@alineo-labs/core";
1
+ import { BashSession, CommandError, ExecConnectionError, LedgerEvent, LedgerEvent as LedgerEvent$1, SandboxError, SandboxHandle, SandboxHandle as SandboxHandle$1, SandboxStatus, StepTimeoutError, reconstructBoundCredentials, resolveBoundCredential } from "@alineo-labs/core";
2
2
  import { CodeLanguage, ControlClient, SandboxState, SnapshotState } from "@alineo-labs/opensandbox";
3
+ import { OpenSandboxCredentialBroker, OpenSandboxCredentialBroker as OpenSandboxCredentialBroker$1 } from "@alineo-labs/vault";
3
4
  //#region src/types.ts
4
5
  /**
5
6
  * Client-side SDK error carrying an HTTP-style status code, thrown for
@@ -104,6 +105,7 @@ var Environment = class {
104
105
  var Sandbox = class {
105
106
  _control;
106
107
  _adapter;
108
+ _credentialBroker;
107
109
  _maxConcurrency;
108
110
  _useServerProxy;
109
111
  _activeCount = 0;
@@ -119,6 +121,7 @@ var Sandbox = class {
119
121
  this._adapter = options.adapter;
120
122
  this._maxConcurrency = options.maxConcurrency;
121
123
  this._useServerProxy = options.useServerProxy ?? false;
124
+ this._credentialBroker = options.credentialBroker ?? new OpenSandboxCredentialBroker$1(this._control, this._useServerProxy);
122
125
  process.setMaxListeners(process.getMaxListeners() + 1);
123
126
  process.on("beforeExit", () => {
124
127
  if (!this._adapterClosed) {
@@ -154,6 +157,8 @@ var Sandbox = class {
154
157
  await this._acquireSlot();
155
158
  const image = typeof opts.image === "string" ? { uri: opts.image } : opts.image;
156
159
  const runId = opts.runId ?? crypto.randomUUID();
160
+ const resourceId = opts.resourceId;
161
+ const teamId = opts.teamId;
157
162
  let sandboxId;
158
163
  try {
159
164
  sandboxId = (await this._control.createSandbox({
@@ -169,7 +174,9 @@ var Sandbox = class {
169
174
  "/dev/null"
170
175
  ],
171
176
  resourceLimits: opts.resources,
172
- timeout: opts.timeout
177
+ timeout: opts.timeout,
178
+ networkPolicy: opts.networkPolicy,
179
+ credentialProxy: opts.credentialProxy ? { enabled: true } : void 0
173
180
  })).id;
174
181
  await this._waitForRunning(sandboxId);
175
182
  const name = opts.name ?? `sandbox-${sandboxId.slice(0, 8)}`;
@@ -182,16 +189,23 @@ var Sandbox = class {
182
189
  payload: {
183
190
  sandboxId,
184
191
  resources: opts.resources,
185
- runId
192
+ runId,
193
+ resourceId,
194
+ teamId,
195
+ networkPolicy: opts.networkPolicy,
196
+ credentialProxy: opts.credentialProxy
186
197
  }
187
198
  });
188
199
  const sb = new SandboxHandle$1(sandboxId, name, {
189
200
  control: this._control,
190
201
  adapter: this._adapter,
202
+ credentialBroker: this._credentialBroker,
191
203
  hooks: opts.hooks,
192
- onClose: () => this._releaseSlot(),
204
+ onClose: () => {
205
+ this._releaseSlot();
206
+ },
193
207
  shell: opts.shell,
194
- fork: (snapshotId, tag, overrideRunId) => this._forkFromSnapshot(snapshotId, name, opts.resources, opts.shell, overrideRunId ?? runId),
208
+ fork: (snapshotId, tag, overrideRunId, forkOpts) => this._forkFromSnapshot(snapshotId, name, opts.resources, opts.shell, overrideRunId ?? runId, sandboxId, resourceId, teamId, forkOpts),
195
209
  useServerProxy: this._useServerProxy
196
210
  });
197
211
  opts.hooks?.onSandboxCreated?.(sandboxId, name);
@@ -228,9 +242,9 @@ var Sandbox = class {
228
242
  await this._ensureConnected();
229
243
  const session = (await this._adapter.listAllSandboxDetails()).find((s) => s.sandboxId === sandboxId);
230
244
  if (!session) throw new SandboxClientError(`Session ${sandboxId} not found`, 404);
231
- return this._resumeSession(session.name, sandboxId, opts?.tag);
245
+ return this._resumeSession(session.name, sandboxId, opts?.tag, opts?.resolveCredential);
232
246
  }
233
- async _resumeSession(name, sandboxId, tag) {
247
+ async _resumeSession(name, sandboxId, tag, resolveCredential) {
234
248
  const entries = await this._adapter.readAll(name, sandboxId);
235
249
  let checkpointIdx;
236
250
  if (tag) {
@@ -241,9 +255,14 @@ var Sandbox = class {
241
255
  if (checkpointIdx === -1) throw new SandboxClientError(`No checkpoint found for session ${sandboxId}`, 404);
242
256
  }
243
257
  const { snapshotId } = entries[checkpointIdx].payload;
244
- const createdEntry = entries.find((e) => e.event === LedgerEvent$1.SandboxCreated);
245
- const resources = (createdEntry?.payload)?.resources;
246
- const runId = (createdEntry?.payload)?.runId ?? crypto.randomUUID();
258
+ const createdPayload = entries.find((e) => e.event === LedgerEvent$1.SandboxCreated)?.payload;
259
+ const resources = createdPayload?.resources;
260
+ const runId = createdPayload?.runId ?? crypto.randomUUID();
261
+ const resourceId = createdPayload?.resourceId;
262
+ const teamId = createdPayload?.teamId;
263
+ const networkPolicy = createdPayload?.networkPolicy;
264
+ const credentialProxy = createdPayload?.credentialProxy;
265
+ const boundCredentials = reconstructBoundCredentials(entries);
247
266
  const replayCache = /* @__PURE__ */ new Map();
248
267
  const pendingStdout = /* @__PURE__ */ new Map();
249
268
  const pendingStderr = /* @__PURE__ */ new Map();
@@ -290,7 +309,9 @@ var Sandbox = class {
290
309
  const newSessionId = (await this._control.createSandbox({
291
310
  snapshotId,
292
311
  resourceLimits: resources,
293
- metadata: { runId }
312
+ metadata: { runId },
313
+ networkPolicy,
314
+ credentialProxy: credentialProxy ? { enabled: true } : void 0
294
315
  })).id;
295
316
  await this._waitForRunning(newSessionId);
296
317
  await this._adapter.append({
@@ -303,16 +324,28 @@ var Sandbox = class {
303
324
  sandboxId: newSessionId,
304
325
  resumedFrom: sandboxId,
305
326
  snapshotId,
306
- runId
327
+ runId,
328
+ resourceId,
329
+ teamId,
330
+ networkPolicy,
331
+ credentialProxy
307
332
  }
308
333
  });
309
- return new SandboxHandle$1(newSessionId, name, {
334
+ const sb = new SandboxHandle$1(newSessionId, name, {
310
335
  control: this._control,
311
336
  adapter: this._adapter,
312
- onClose: () => this._releaseSlot(),
313
- fork: resources?.cpu && resources?.memory ? (snapshotId, tag, overrideRunId) => this._forkFromSnapshot(snapshotId, name, resources, void 0, overrideRunId ?? runId) : void 0,
337
+ credentialBroker: this._credentialBroker,
338
+ onClose: () => {
339
+ this._releaseSlot();
340
+ },
341
+ fork: resources?.cpu && resources.memory ? (snapshotId, tag, overrideRunId, forkOpts) => this._forkFromSnapshot(snapshotId, name, resources, void 0, overrideRunId ?? runId, newSessionId, resourceId, teamId, forkOpts) : void 0,
314
342
  useServerProxy: this._useServerProxy
315
343
  }, replayCache, pendingInteractive);
344
+ for (const [credName, { binding, source }] of boundCredentials) {
345
+ const value = await resolveBoundCredential(credName, source, resolveCredential, newSessionId);
346
+ await sb.credentials.set(credName, value, binding, source);
347
+ }
348
+ return sb;
316
349
  } catch (err) {
317
350
  this._releaseSlot();
318
351
  throw err;
@@ -355,8 +388,11 @@ var Sandbox = class {
355
388
  return new SandboxHandle$1(sandboxId, name, {
356
389
  control: this._control,
357
390
  adapter: this._adapter,
358
- onClose: () => this._releaseSlot(),
359
- fork: resources ? (snapshotId, tag, overrideRunId) => this._forkFromSnapshot(snapshotId, name, resources, void 0, overrideRunId ?? opts?.runId) : void 0,
391
+ credentialBroker: this._credentialBroker,
392
+ onClose: () => {
393
+ this._releaseSlot();
394
+ },
395
+ fork: resources ? (snapshotId, tag, overrideRunId, forkOpts) => this._forkFromSnapshot(snapshotId, name, resources, void 0, overrideRunId ?? opts?.runId, sandboxId, opts?.resourceId, opts?.teamId, forkOpts) : void 0,
360
396
  useServerProxy: this._useServerProxy
361
397
  });
362
398
  }
@@ -384,7 +420,7 @@ var Sandbox = class {
384
420
  * await sb2.close();
385
421
  * ```
386
422
  */
387
- async restoreSnapshot(snapshotId, name, resources, runId) {
423
+ async restoreSnapshot(snapshotId, name, resources, runId, opts) {
388
424
  await this._ensureConnected();
389
425
  await this._acquireSlot();
390
426
  try {
@@ -392,7 +428,9 @@ var Sandbox = class {
392
428
  const newId = (await this._control.createSandbox({
393
429
  snapshotId,
394
430
  resourceLimits: resources,
395
- metadata: { runId: finalRunId }
431
+ metadata: { runId: finalRunId },
432
+ networkPolicy: opts?.networkPolicy,
433
+ credentialProxy: opts?.credentialProxy ? { enabled: true } : void 0
396
434
  })).id;
397
435
  await this._waitForRunning(newId);
398
436
  await this._adapter.append({
@@ -404,14 +442,21 @@ var Sandbox = class {
404
442
  payload: {
405
443
  sandboxId: newId,
406
444
  fromSnapshot: snapshotId,
407
- runId: finalRunId
445
+ runId: finalRunId,
446
+ resourceId: opts?.resourceId,
447
+ teamId: opts?.teamId,
448
+ networkPolicy: opts?.networkPolicy,
449
+ credentialProxy: opts?.credentialProxy
408
450
  }
409
451
  });
410
452
  return new SandboxHandle$1(newId, name, {
411
453
  control: this._control,
412
454
  adapter: this._adapter,
413
- onClose: () => this._releaseSlot(),
414
- fork: (snapshotId, tag, overrideRunId) => this._forkFromSnapshot(snapshotId, name, resources, void 0, overrideRunId ?? finalRunId),
455
+ credentialBroker: this._credentialBroker,
456
+ onClose: () => {
457
+ this._releaseSlot();
458
+ },
459
+ fork: (snapshotId, tag, overrideRunId, forkOpts) => this._forkFromSnapshot(snapshotId, name, resources, void 0, overrideRunId ?? finalRunId, newId, opts?.resourceId, opts?.teamId, forkOpts),
415
460
  useServerProxy: this._useServerProxy
416
461
  });
417
462
  } catch (err) {
@@ -563,6 +608,8 @@ var Sandbox = class {
563
608
  })).id;
564
609
  await this._waitForRunning(newId);
565
610
  const sessionName = `env-${envName}-${newId.slice(0, 8)}`;
611
+ const resourceId = extra?.resourceId;
612
+ const teamId = extra?.teamId;
566
613
  await this._adapter.append({
567
614
  ts: Date.now(),
568
615
  name: sessionName,
@@ -573,16 +620,21 @@ var Sandbox = class {
573
620
  sandboxId: newId,
574
621
  fromEnvironment: envName,
575
622
  snapshotId,
576
- runId
623
+ runId,
624
+ resourceId,
625
+ teamId
577
626
  }
578
627
  });
579
628
  const sb = new SandboxHandle$1(newId, sessionName, {
580
629
  control: this._control,
581
630
  adapter: this._adapter,
631
+ credentialBroker: this._credentialBroker,
582
632
  hooks: extra?.hooks,
583
- onClose: () => this._releaseSlot(),
633
+ onClose: () => {
634
+ this._releaseSlot();
635
+ },
584
636
  shell: extra?.shell ?? envShell,
585
- fork: (snapshotId, tag, overrideRunId) => this._forkFromSnapshot(snapshotId, sessionName, resources, extra?.shell ?? envShell, overrideRunId ?? runId),
637
+ fork: (snapshotId, tag, overrideRunId, forkOpts) => this._forkFromSnapshot(snapshotId, sessionName, resources, extra?.shell ?? envShell, overrideRunId ?? runId, newId, resourceId, teamId, forkOpts),
586
638
  useServerProxy: this._useServerProxy
587
639
  });
588
640
  extra?.hooks?.onSandboxCreated?.(newId, sessionName);
@@ -592,14 +644,18 @@ var Sandbox = class {
592
644
  throw err;
593
645
  }
594
646
  }
595
- async _forkFromSnapshot(snapshotId, parentName, resources, shell, runId) {
647
+ async _forkFromSnapshot(snapshotId, parentName, resources, shell, runId, parentSandboxId, resourceId, teamId, forkOpts) {
596
648
  await this._acquireSlot();
597
649
  try {
598
650
  const finalRunId = runId ?? crypto.randomUUID();
651
+ const finalResourceId = forkOpts?.resourceId ?? resourceId;
652
+ const finalTeamId = forkOpts?.teamId ?? teamId;
599
653
  const newId = (await this._control.createSandbox({
600
654
  snapshotId,
601
655
  resourceLimits: resources,
602
- metadata: { runId: finalRunId }
656
+ metadata: { runId: finalRunId },
657
+ networkPolicy: forkOpts?.networkPolicy,
658
+ credentialProxy: forkOpts?.credentialProxy ? { enabled: true } : void 0
603
659
  })).id;
604
660
  await this._waitForRunning(newId);
605
661
  const sessionName = `fork-${parentName}-${newId.slice(0, 8)}`;
@@ -612,15 +668,23 @@ var Sandbox = class {
612
668
  payload: {
613
669
  sandboxId: newId,
614
670
  forkedFrom: snapshotId,
615
- runId: finalRunId
671
+ runId: finalRunId,
672
+ resourceId: finalResourceId,
673
+ teamId: finalTeamId,
674
+ parentSandboxId,
675
+ networkPolicy: forkOpts?.networkPolicy,
676
+ credentialProxy: forkOpts?.credentialProxy
616
677
  }
617
678
  });
618
679
  return new SandboxHandle$1(newId, sessionName, {
619
680
  control: this._control,
620
681
  adapter: this._adapter,
621
- onClose: () => this._releaseSlot(),
682
+ credentialBroker: this._credentialBroker,
683
+ onClose: () => {
684
+ this._releaseSlot();
685
+ },
622
686
  shell,
623
- fork: (sid, tag, overrideRunId) => this._forkFromSnapshot(sid, sessionName, resources, shell, overrideRunId ?? finalRunId),
687
+ fork: (sid, tag, overrideRunId, nextForkOpts) => this._forkFromSnapshot(sid, sessionName, resources, shell, overrideRunId ?? finalRunId, newId, finalResourceId, finalTeamId, nextForkOpts),
624
688
  useServerProxy: this._useServerProxy
625
689
  });
626
690
  } catch (err) {
@@ -654,4 +718,4 @@ var Sandbox = class {
654
718
  }
655
719
  };
656
720
  //#endregion
657
- export { BashSession, CodeLanguage, CommandError, Environment, ExecConnectionError, LedgerEvent, Sandbox, SandboxClientError, SandboxError, SandboxHandle, SandboxStatus, StepTimeoutError };
721
+ export { BashSession, CodeLanguage, CommandError, Environment, ExecConnectionError, LedgerEvent, OpenSandboxCredentialBroker, Sandbox, SandboxClientError, SandboxError, SandboxHandle, SandboxStatus, StepTimeoutError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alineo-labs/sandbox",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,8 +29,9 @@
29
29
  "test:watch": "vitest"
30
30
  },
31
31
  "dependencies": {
32
- "@alineo-labs/core": "0.2.0",
33
- "@alineo-labs/opensandbox": "0.1.0"
32
+ "@alineo-labs/core": "0.3.0",
33
+ "@alineo-labs/opensandbox": "0.2.0",
34
+ "@alineo-labs/vault": "0.2.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "bun-types": "1.3.14",