@tangle-network/sandbox 0.11.1 → 0.12.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.
@@ -1,4 +1,5 @@
1
- import { $ as DurablePlan, Bn as RolloutStartResult, Cr as SandboxInfo, D as CodeExecutionOptions, Ei as TeePublicKeyResponse, Er as SandboxPortBinding, Fi as WaitForRolloutOptions, Fn as ResumeOptions, G as DispatchPromptOptions, Gn as SSHCredentials, Gt as IntelligenceReport, H as CreateTaskSessionOptions, Hr as SandboxTraceOptions, Ii as WriteFileOptions, In as Rollout, K as DispatchedSession, Kr as SearchMatch, Kt as IntelligenceReportBudget, Li as WriteManyFile, Lr as SandboxTerminalManager, M as CommitTaskSessionOptions, Mt as GitStatus, N as CompletedTurnResult, Nr as SandboxRuntimeProfileList, Nt as GpuLease, O as CodeExecutionResult, Ot as GitBranch, Pi as WaitForOptions, Pn as RestoreSnapshotOptions, Pr as SandboxStatus, Qr as SentSessionMessage, Ri as WriteManyOptions, Rn as RolloutOptions, Rt as GpuLeaseManager, Si as TeeAttestationOptions, Sn as ProvisionResult, V as CreateSessionOptions, Wn as SSHCommandDescriptor, Wr as ScopedToken, Wt as InstalledTool, Xr as SendSessionMessageOptions, Xt as JsonValue, Y as DriveTurnOptions, Yn as SandboxEvent, Yt as IntelligenceReportWindow, Z as DriverInfo, Zr as SendSessionMessageRequest, Zt as ListMessagesOptions, _i as TaskSessionChanges, an as NetworkManager, at as ExecResult, bi as TaskSessionInfo, bn as PromptResult, ci as SnapshotOptions, cn as PermissionsManager, di as StartupDiagnostics, ei as SessionEventStreamOptions, et as EgressManager, ft as FileSystem, gi as TaskResult, gt as FileWriteResult, hi as TaskOptions, ii as SessionMessage, it as ExecOptions, jr as SandboxRuntimeHealth, jt as GitDiff, k as CodeLanguage, ki as TurnDriveResult, kr as SandboxResourceUsage, kt as GitCommit, l as BackendManager, li as SnapshotResult, mn as ProcessManager, mr as SandboxFleetTraceBundle, ni as SessionInfo, nn as MintScopedTokenOptions, nt as EventStreamOptions, qn as SandboxConnection, qr as SearchOptions, qt as IntelligenceReportCompareTo, ri as SessionListOptions, s as BackendConfig, si as SnapshotInfo, ti as SessionForkOptions, un as PreviewLinkManager, vi as TaskSessionCommitResult, vn as PromptInputPart, w as BranchOptions, wi as TeeAttestationResponse, xn as ProvisionEvent, yn as PromptOptions, zr as SandboxTraceBundle } from "./types-D2C72ySk.js";
1
+ import { $ as EventStreamOptions, $r as SendSessionMessageRequest, At as GitDiff, Bi as WriteManyOptions, Bn as RolloutStartResult, Br as SandboxTerminals, C as CodeExecutionResult, Cr as SandboxInfo, D as CommitTaskSessionOptions, Dt as GitBranch, Ei as TeeAttestationResponse, Er as SandboxPortBinding, Fn as ResumeOptions, Fr as SandboxTerminalAttachOptions, G as DriveTurnOptions, Gn as SSHCredentials, Gt as IntelligenceReportBudget, H as DispatchedSession, I as CreateSessionOptions, Ii as WaitForOptions, In as Rollout, Jr as SearchMatch, Jt as IntelligenceReportWindow, Kr as ScopedToken, Kt as IntelligenceReportCompareTo, L as CreateTaskSessionOptions, Li as WaitForRolloutOptions, Lt as GpuLeaseManager, Mt as GpuLease, Nr as SandboxRuntimeProfileList, O as CompletedTurnResult, Oi as TeePublicKeyResponse, Ot as GitCommit, Pn as RestoreSnapshotOptions, Pr as SandboxStatus, Qi as TerminalStreamHandlers, Qr as SendSessionMessageOptions, Ri as WriteFileOptions, Rn as RolloutOptions, S as CodeExecutionOptions, Si as TaskSessionInfo, Sn as ProvisionResult, Ut as InstalledTool, V as DispatchPromptOptions, Vr as SandboxTraceBundle, Wn as SSHCommandDescriptor, Wr as SandboxTraceOptions, Wt as IntelligenceReport, X as EgressManager, Xt as ListMessagesOptions, Y as DurablePlan, Yi as TerminalStream, Yn as SandboxEvent, Yr as SearchOptions, Yt as JsonValue, _i as TaskOptions, ai as SessionListOptions, bi as TaskSessionCommitResult, bn as PromptResult, di as SnapshotResult, ei as SentSessionMessage, ht as FileWriteResult, ii as SessionInfo, in as NetworkManager, ji as TurnDriveResult, jr as SandboxRuntimeHealth, jt as GitStatus, kr as SandboxResourceUsage, l as BackendManager, li as SnapshotInfo, ln as PreviewLinkManager, lt as FileSystem, mn as ProcessManager, mr as SandboxFleetTraceBundle, ni as SessionEventStreamOptions, nt as ExecResult, oi as SessionMessage, pi as StartupDiagnostics, q as DriverInfo, qn as SandboxConnection, ri as SessionForkOptions, s as BackendConfig, sn as PermissionsManager, tn as MintScopedTokenOptions, tt as ExecOptions, ui as SnapshotOptions, vi as TaskResult, vn as PromptInputPart, w as CodeLanguage, wi as TeeAttestationOptions, xn as ProvisionEvent, y as BranchOptions, yi as TaskSessionChanges, yn as PromptOptions, zi as WriteManyFile } from "./types-C67osezQ.js";
2
+ import { AgentProfile } from "@tangle-network/agent-interface";
2
3
 
3
4
  //#region src/mcp.d.ts
4
5
  /**
@@ -112,18 +113,6 @@ declare function buildControlPlaneMcpConfig(options: BuildControlPlaneMcpConfigO
112
113
  };
113
114
  //#endregion
114
115
  //#region src/interactive.d.ts
115
- /**
116
- * Interactive harness sessions on the public SDK.
117
- *
118
- * `box.session(id).interactive()` returns a handle that spawns a coding
119
- * harness's native interactive TUI in the sandbox (start), drives it with
120
- * prompts (sendPrompt), and tears it down (stop). The live framebuffer is
121
- * streamed over the WebSocket at the returned `streamUrl` (the secured
122
- * `/terminals/:id/ws` pixel lane) — open it with your terminal/xterm client.
123
- *
124
- * This is the public SDK surface of the Session Protocol Gateway; it rides the
125
- * same secured runtime routes as the rest of the SDK.
126
- */
127
116
  /** CLI auth file materialized into the harness's auth home before launch. */
128
117
  interface InteractiveAuthFile {
129
118
  path: string;
@@ -131,7 +120,12 @@ interface InteractiveAuthFile {
131
120
  mode?: number;
132
121
  }
133
122
  interface StartInteractiveOptions {
134
- /** Harness with a native interactive TUI: "claude-code" | "codex" | "kimi-code". */
123
+ /**
124
+ * Harness with a native interactive TUI (bare binary launches it): e.g.
125
+ * "claude-code", "codex", "opencode", "kimi-code", "factory-droids",
126
+ * "forge", "pi", "amp", "hermes". The sidecar's harness registry is the
127
+ * authority; it rejects harnesses without a TUI entrypoint (e.g. "cursor").
128
+ */
135
129
  harness: string;
136
130
  model?: string;
137
131
  apiKey?: string;
@@ -142,6 +136,20 @@ interface StartInteractiveOptions {
142
136
  cols?: number;
143
137
  rows?: number;
144
138
  authFiles?: InteractiveAuthFile[];
139
+ /**
140
+ * Canonical agent profile (persona, skills, tool policy, MCP). When set, the
141
+ * sidecar materializes it into `cwd` before spawning the TUI, so the
142
+ * interactive session runs AS the configured agent rather than a bare harness.
143
+ * Omit to launch the harness's default TUI.
144
+ */
145
+ profile?: AgentProfile;
146
+ /**
147
+ * Opening message the TUI submits on its own once ready (via the harness's
148
+ * prompt launch arg). Use this to start the agent working immediately instead
149
+ * of writing keystrokes after start — a TUI drops input sent before it is
150
+ * ready to read. Omit for a session that opens idle.
151
+ */
152
+ initialPrompt?: string;
145
153
  }
146
154
  interface InteractiveSessionInfo {
147
155
  sessionId: string;
@@ -154,6 +162,47 @@ interface InteractiveSessionInfo {
154
162
  */
155
163
  streamUrl: string;
156
164
  }
165
+ /**
166
+ * Snapshot of an interactive session's lifecycle: still running, or exited
167
+ * with its exit code (served from the sidecar's bounded exit tombstone).
168
+ * `status()` returns `null` when the sidecar no longer knows the id — never
169
+ * started, tombstone evicted, or superseded by a restart under the same id.
170
+ */
171
+ type InteractiveSessionStatus = {
172
+ state: "running";
173
+ sessionId: string;
174
+ harness: string;
175
+ startedAt: string;
176
+ streamUrl: string;
177
+ } | {
178
+ state: "exited";
179
+ sessionId: string;
180
+ harness: string;
181
+ startedAt: string;
182
+ endedAt: string;
183
+ exitCode?: number;
184
+ exitSignal?: string;
185
+ /**
186
+ * "exited" = the process ended on its own; "stopped" = explicit stop();
187
+ * "lost" = the session was interrupted by a sidecar restart mid-run (its
188
+ * PTY died with the process) and re-hydrated as a durable tombstone rather
189
+ * than reported as a 404/null. A "lost" session is a failed run.
190
+ */
191
+ reason: "exited" | "stopped" | "lost";
192
+ };
193
+ /** Options for `InteractiveSessionHandle.attach()`. */
194
+ interface InteractiveAttachOptions {
195
+ /** Initial PTY geometry reported in the attach init frame. */
196
+ cols?: number;
197
+ rows?: number;
198
+ /**
199
+ * Stream callbacks, bound before the socket opens. Register `onData` here:
200
+ * the server replays the session's buffered screen immediately after the
201
+ * attach acknowledgement, so a handler added after `attach()` resolves
202
+ * would miss the replayed frames.
203
+ */
204
+ handlers?: TerminalStreamHandlers;
205
+ }
157
206
  /** Decision passed to `respondToPermission`. */
158
207
  interface RespondToPermissionOptions {
159
208
  /** The human's decision for the awaiting permission interaction. */
@@ -178,6 +227,19 @@ interface InteractiveSessionHost {
178
227
  _startInteractive(id: string, options: StartInteractiveOptions): Promise<InteractiveSessionInfo>;
179
228
  _sendInteractivePrompt(id: string, prompt: string): Promise<void>;
180
229
  _stopInteractive(id: string): Promise<void>;
230
+ /**
231
+ * Optional so adding it does not break existing implementers of this exported
232
+ * interface (a required addition is a breaking change; this is additive). A
233
+ * host that omits it makes `InteractiveSessionHandle.status()` reject with a
234
+ * clear "not supported" error instead of failing to compile downstream.
235
+ */
236
+ _interactiveStatus?(id: string): Promise<InteractiveSessionStatus | null>;
237
+ /**
238
+ * Optional for the same additive-change reason as `_interactiveStatus`. A
239
+ * host that omits it makes `InteractiveSessionHandle.attach()` reject with
240
+ * a clear "not supported" error.
241
+ */
242
+ _attachInteractive?(id: string, options?: InteractiveAttachOptions): Promise<TerminalStream>;
181
243
  }
182
244
  /**
183
245
  * Handle for one session's interactive harness. Obtained via
@@ -190,13 +252,34 @@ declare class InteractiveSessionHandle {
190
252
  constructor(host: InteractiveSessionHost, sessionId: string);
191
253
  /**
192
254
  * Spawn the harness's interactive TUI for this session. Returns the
193
- * `streamUrl` to attach a terminal client to. Throws if the harness has no
194
- * interactive entrypoint (e.g. opencode), the binary is not installed, or a
195
- * session is already running for this id.
255
+ * `streamUrl` of the live framebuffer — open it programmatically with
256
+ * `attach()`, or hand it to a terminal frontend. Throws if the harness has
257
+ * no interactive entrypoint (e.g. cursor, which is SDK-only), the binary is
258
+ * not installed, or a session is already running for this id.
196
259
  */
197
260
  start(options: StartInteractiveOptions): Promise<InteractiveSessionInfo>;
198
261
  /** Inject a prompt as keystrokes into the live harness (submitted on send). */
199
262
  sendPrompt(prompt: string): Promise<void>;
263
+ /**
264
+ * Attach to the live harness PTY as a {@link TerminalStream}: the same PTY
265
+ * the interactive TUI runs in (the sidecar keys it by this session id), so
266
+ * the stream sees the harness's screen and its keystrokes drive the
267
+ * harness — never a fresh shell. The host mints a short-lived scoped
268
+ * terminal token and dials the session's `streamUrl` through the secured
269
+ * sidecar proxy; resolves once the server acknowledges the attach (the
270
+ * buffered screen then replays through `handlers.onData`).
271
+ *
272
+ * Throws when no interactive session is running for this id — attach after
273
+ * `start()`, or to a session another caller started.
274
+ */
275
+ attach(options?: InteractiveAttachOptions): Promise<TerminalStream>;
276
+ /**
277
+ * Observe the session: running, exited (with its exit code), or `null`
278
+ * when the sidecar no longer knows the id. Poll this to detect completion —
279
+ * an interactive session has no structured result stream, so the exit
280
+ * tombstone is the completion signal.
281
+ */
282
+ status(): Promise<InteractiveSessionStatus | null>;
200
283
  /** Stop the interactive harness and reap its PTY. */
201
284
  stop(): Promise<void>;
202
285
  }
@@ -212,7 +295,7 @@ interface SandboxSessionHost extends InteractiveSessionHost {
212
295
  prompt(message: string | PromptInputPart[], options?: PromptOptions): Promise<PromptResult>;
213
296
  _sessionStatus(id: string): Promise<SessionInfo | null>;
214
297
  _sessionEvents(id: string, opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
215
- _sessionResult(id: string): Promise<PromptResult>;
298
+ _sessionResult(id: string, session?: SessionInfo): Promise<PromptResult>;
216
299
  _sessionCancel(id: string): Promise<void>;
217
300
  _sessionDelete(id: string): Promise<void>;
218
301
  _sessionSendMessage(id: string, request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
@@ -263,9 +346,10 @@ declare class SandboxSession {
263
346
  */
264
347
  events(opts?: SessionEventStreamOptions): AsyncGenerator<SandboxEvent>;
265
348
  /**
266
- * Await the session's terminal result. Polls status + drains events
267
- * until the session reaches a terminal state, then returns the
268
- * aggregated `PromptResult`.
349
+ * Await the session's terminal result. Reads status and drains events
350
+ * from the latest execution until the session reaches a terminal state,
351
+ * then returns the aggregated `PromptResult`. Event replay makes this safe
352
+ * to call after the execution has already finished.
269
353
  *
270
354
  * Use this to wait for a session that was started by another caller
271
355
  * (e.g. `dispatchPrompt`).
@@ -283,8 +367,10 @@ declare class SandboxSession {
283
367
  */
284
368
  prompt(message: string | PromptInputPart[], opts?: PromptOptions): Promise<PromptResult>;
285
369
  /**
286
- * Send a structured message through the session message endpoint. Model and
287
- * message identifiers are translated to the runtime's wire names by the SDK.
370
+ * Submit a structured message through the session message endpoint. The
371
+ * returned receipt confirms admission; follow progress with `events()` or
372
+ * await the terminal response with `result()`. Model and message identifiers
373
+ * are translated to the runtime's wire names by the SDK.
288
374
  */
289
375
  sendMessage(request: SendSessionMessageRequest, options?: SendSessionMessageOptions): Promise<SentSessionMessage>;
290
376
  /**
@@ -384,6 +470,67 @@ declare function exportTraceBundle(bundle: TraceExportBundle, sink: TraceExportS
384
470
  declare function toOtelJson(bundle: TraceExportBundle, serviceName?: string): JsonObject;
385
471
  declare function otelTraceIdForTangleTrace(traceId: string): string;
386
472
  //#endregion
473
+ //#region ../../../packages/runtime-contracts/dist/workspace-image-types.d.ts
474
+ /** A port declared by the published OCI image. */
475
+ interface WorkspaceImageExposedPort {
476
+ port: number;
477
+ protocol: "tcp" | "udp" | "sctp";
478
+ }
479
+ /** Successful workspace image publication returned by the Sandbox API. */
480
+ interface WorkspaceImagePublishResult$1 {
481
+ /** Immutable registry reference. */
482
+ image: string;
483
+ /** Operation-stable tag used during publication. */
484
+ taggedImage: string;
485
+ digest: string;
486
+ imageId: string;
487
+ sizeBytes: number;
488
+ contextBytes: number;
489
+ contextEntries: number;
490
+ buildDurationMs: number;
491
+ pushDurationMs: number;
492
+ /** Network ports from the final image configuration, not source inspection. */
493
+ exposedPorts: WorkspaceImageExposedPort[];
494
+ }
495
+ //#endregion
496
+ //#region src/workspace-images.d.ts
497
+ interface WorkspaceImagePublishInput {
498
+ /** Workspace-relative build context. */
499
+ contextPath?: string;
500
+ /** Dockerfile path relative to the build context. */
501
+ dockerfilePath?: string;
502
+ /** Registry host and repository path, without a scheme, tag, or digest. */
503
+ repository: string;
504
+ /** Registry credential used only by the trusted image publisher. */
505
+ auth: {
506
+ username: string;
507
+ password: string;
508
+ };
509
+ platform?: "linux/amd64" | "linux/arm64";
510
+ }
511
+ type WorkspaceImagePublishResult = WorkspaceImagePublishResult$1;
512
+ interface WorkspaceImageHttpClient {
513
+ fetch(path: string, options?: RequestInit, fetchOptions?: {
514
+ timeoutMs?: number;
515
+ }): Promise<Response>;
516
+ }
517
+ interface WorkspaceImagePublishRequestOptions {
518
+ /** Stable key to safely retry the same logical publication. */
519
+ idempotencyKey?: string;
520
+ /** Maximum client wait. The server independently caps the operation. */
521
+ timeoutMs?: number;
522
+ signal?: AbortSignal;
523
+ }
524
+ /** Builds and publishes the current sandbox workspace from trusted hosts. */
525
+ declare class WorkspaceImages {
526
+ private readonly client;
527
+ private readonly sandboxId;
528
+ private readonly ensureRunning;
529
+ private readonly filesystemIncarnationId;
530
+ constructor(client: WorkspaceImageHttpClient, sandboxId: string, ensureRunning: () => Promise<void>, filesystemIncarnationId: () => string | undefined);
531
+ publish(input: WorkspaceImagePublishInput, options?: WorkspaceImagePublishRequestOptions): Promise<WorkspaceImagePublishResult>;
532
+ }
533
+ //#endregion
387
534
  //#region src/sandbox.d.ts
388
535
  /**
389
536
  * Result of registering a sidecar session mapping. `reprovisionRequired` is
@@ -456,13 +603,34 @@ interface ToolsCapability {
456
603
  declare class SandboxInstance {
457
604
  private readonly client;
458
605
  private info;
606
+ /** Once observed, incarnation metadata is authoritative for this handle. */
607
+ private filesystemIncarnationContract;
608
+ private refreshInFlight?;
459
609
  private readonly defaultRuntimeBackend?;
460
610
  private readonly runtime;
611
+ private readonly workspaceImages;
612
+ /**
613
+ * A profile the runtime has cached (create-time priming), letting turns
614
+ * send `backend.profileSha256` instead of re-shipping the profile's static
615
+ * corpus. Set only when priming succeeded; when unset every turn sends the
616
+ * full profile (unchanged legacy behavior). `snapshot` is the serialized
617
+ * content at prime time — a turn substitutes the reference only when the
618
+ * outgoing profile serializes identically, so a caller that mutates the
619
+ * profile in place (or passes an equivalent object) is compared by CONTENT,
620
+ * never by object identity, and a changed profile is sent inline.
621
+ */
622
+ private deferredProfileReference?;
461
623
  constructor(client: HttpClient, info: SandboxInfo, defaultRuntimeBackend?: BackendConfig);
462
624
  /** Unique sandbox identifier */
463
625
  get id(): string;
464
626
  /** Human-readable name */
465
627
  get name(): string | undefined;
628
+ /** Identity of the currently published filesystem contents. */
629
+ get filesystemIncarnationId(): string | undefined;
630
+ /** How the current filesystem contents were acquired. */
631
+ get filesystemIncarnationProvenance(): "fresh" | "restored" | "unknown" | undefined;
632
+ /** Whether the current incarnation is safe to use as authoritative state. */
633
+ get filesystemIncarnationReadiness(): "transitioning" | "ready" | undefined;
466
634
  /** Current status */
467
635
  get status(): SandboxStatus;
468
636
  /** Connection information */
@@ -483,6 +651,8 @@ declare class SandboxInstance {
483
651
  get gpuLease(): GpuLease | undefined;
484
652
  /** Web terminal URL for browser-based access */
485
653
  get url(): string | undefined;
654
+ /** Build and publish this sandbox's workspace without exposing registry credentials to it. */
655
+ get images(): WorkspaceImages;
486
656
  /**
487
657
  * The 12-phase startup breakdown (storage_provision, host_select, edge_bind,
488
658
  * edge_ready, egress_proxy, docker_pull/create/start, sidecar_boot,
@@ -556,6 +726,7 @@ declare class SandboxInstance {
556
726
  * Refresh sandbox information from the server.
557
727
  */
558
728
  refresh(): Promise<void>;
729
+ private refreshInfo;
559
730
  /**
560
731
  * Fetch fresh TEE attestation evidence for this sandbox.
561
732
  *
@@ -708,6 +879,32 @@ declare class SandboxInstance {
708
879
  * received. Reconnection is transparent — replayed events that were
709
880
  * already yielded (based on event ID tracking) are deduplicated.
710
881
  */
882
+ /**
883
+ * Record that the runtime holds `profile` under `sha256` (from create-time
884
+ * priming), so later turns can reference it by hash. Captures a content
885
+ * snapshot so a later mutation of the same object is detected and sent
886
+ * inline. Internal — called by the client after a successful prime; never
887
+ * part of the public surface.
888
+ */
889
+ _setDeferredProfileReference(profile: object, sha256: string): void;
890
+ /**
891
+ * Store `profile` on the runtime and record its hash so subsequent turns
892
+ * send `backend.profileSha256` instead of the full corpus. Internal; called
893
+ * by the client after the sandbox is running. Throws on transport/HTTP
894
+ * failure — the caller decides whether a prime failure is fatal (it is not:
895
+ * turns fall back to sending the full profile inline).
896
+ */
897
+ _primeDeferredProfile(profile: object): Promise<string>;
898
+ /**
899
+ * Build the run request's `backend` body. When the outgoing profile's CONTENT
900
+ * matches the one the runtime already holds (and we are not resending after a
901
+ * cache miss), swap the inline `profile` for its `profileSha256` so a large
902
+ * static corpus does not ride every turn. The match is by serialized content,
903
+ * not object identity, so a mutated-in-place profile — or an equivalent
904
+ * object passed as a per-turn override — is compared correctly: unchanged
905
+ * content references by hash, changed content sends inline (the legacy shape).
906
+ */
907
+ private buildRunBackendBody;
711
908
  streamPrompt(message: string | PromptInputPart[], options?: PromptOptions): AsyncGenerator<SandboxEvent>;
712
909
  /**
713
910
  * Inner prompt stream: opens the SSE connection and reconnects on silent
@@ -818,8 +1015,12 @@ declare class SandboxInstance {
818
1015
  runtimeHealth(): Promise<SandboxRuntimeHealth>;
819
1016
  /** Return the runtime's current listening-port snapshot. */
820
1017
  ports(): Promise<SandboxPortBinding[]>;
821
- /** Interactive terminal operations for this runtime. */
822
- get terminals(): SandboxTerminalManager;
1018
+ /**
1019
+ * Interactive terminal operations for this runtime: the REST manager
1020
+ * (create/input/list/get) plus `attach()`, which opens the live terminal
1021
+ * WebSocket as a {@link TerminalStream}.
1022
+ */
1023
+ get terminals(): SandboxTerminals;
823
1024
  /** List profiles installed in this sandbox runtime. */
824
1025
  listProfiles(): Promise<SandboxRuntimeProfileList>;
825
1026
  /**
@@ -907,6 +1108,7 @@ declare class SandboxInstance {
907
1108
  get fs(): FileSystem;
908
1109
  private fsReadBatch;
909
1110
  private fsTree;
1111
+ private fsUsage;
910
1112
  private fsUpload;
911
1113
  /** See {@link FileSystem.uploadData}. Delegates to the shared, browser-safe
912
1114
  * chunked-upload flow in `lib/chunked-upload.ts`, wired to this sandbox's
@@ -1034,6 +1236,7 @@ declare class SandboxInstance {
1034
1236
  * ```
1035
1237
  */
1036
1238
  get process(): ProcessManager;
1239
+ private processEnsureDevServer;
1037
1240
  private processSpawn;
1038
1241
  private processSpawnExact;
1039
1242
  private processRunCode;
@@ -1339,6 +1542,10 @@ declare class SandboxInstance {
1339
1542
  /**
1340
1543
  * Wait for the sandbox to reach a specific status.
1341
1544
  *
1545
+ * A sandbox using the filesystem-incarnation contract is not considered
1546
+ * `running` until that incarnation is ready. Legacy servers that omit the
1547
+ * contract retain the status-only behavior.
1548
+ *
1342
1549
  * When `onProgress` is provided and the sandbox is still provisioning,
1343
1550
  * uses SSE events for real-time progress instead of polling. Falls back
1344
1551
  * to polling if the SSE connection fails or is unavailable.
@@ -1366,7 +1573,9 @@ declare class SandboxInstance {
1366
1573
  * delivers progress callbacks while waiting for a target status.
1367
1574
  */
1368
1575
  private waitForWithSSE;
1576
+ private hasReachedWaitTarget;
1369
1577
  private ensureRunning;
1578
+ private assertFilesystemIncarnationReady;
1370
1579
  private runtimeFetch;
1371
1580
  /**
1372
1581
  * Delegates to the shared `parseSSEStream` in `lib/sse-parser.ts`
@@ -1389,13 +1598,13 @@ declare class SandboxInstance {
1389
1598
  * ```typescript
1390
1599
  * await box.registerSessionMapping({
1391
1600
  * sessionId: "sess_abc",
1392
- * userId: "user_123",
1601
+ * runtimeSessionId: "runtime_abc",
1393
1602
  * });
1394
1603
  * ```
1395
1604
  */
1396
1605
  registerSessionMapping(opts: {
1397
- sessionId: string;
1398
- userId: string; /** The runtime (sidecar) session id this agent session routes to. */
1606
+ sessionId: string; /** @deprecated Ownership is derived from the Sandbox API key. */
1607
+ userId?: string; /** The runtime (sidecar) session id this agent session routes to. */
1399
1608
  runtimeSessionId: string; /** Optional container id for direct routing. */
1400
1609
  sidecarId?: string; /** Optional projectRef so the server can detect a stale sidecar. */
1401
1610
  projectRef?: string;
@@ -1406,8 +1615,8 @@ declare class SandboxInstance {
1406
1615
  * sandbox stays alive.
1407
1616
  */
1408
1617
  unregisterSessionMapping(opts: {
1409
- sessionId: string;
1410
- userId: string;
1618
+ sessionId: string; /** @deprecated Ownership is derived from the Sandbox API key. */
1619
+ userId?: string;
1411
1620
  }): Promise<{
1412
1621
  success: boolean;
1413
1622
  sessionId: string;
@@ -1530,7 +1739,7 @@ declare class SandboxInstance {
1530
1739
  /** @internal — invoked by SandboxSession.events(). */
1531
1740
  _sessionEvents(id: string, opts?: SessionEventStreamOptions, stopOnTurnTerminal?: boolean): AsyncGenerator<SandboxEvent>;
1532
1741
  /** @internal — invoked by SandboxSession.result(). */
1533
- _sessionResult(id: string): Promise<PromptResult>;
1742
+ _sessionResult(id: string, knownSession?: SessionInfo): Promise<PromptResult>;
1534
1743
  /**
1535
1744
  * @internal — invoked by SandboxSession.cancel(). Void-returning alias of
1536
1745
  * `_interrupt`: both abort the in-flight execution via `POST /{id}/abort`
@@ -1543,6 +1752,33 @@ declare class SandboxInstance {
1543
1752
  _startInteractive(id: string, options: StartInteractiveOptions): Promise<InteractiveSessionInfo>;
1544
1753
  /** @internal — invoked by InteractiveSessionHandle.sendPrompt(). */
1545
1754
  _sendInteractivePrompt(id: string, prompt: string): Promise<void>;
1755
+ /** @internal — invoked by InteractiveSessionHandle.status(). */
1756
+ _interactiveStatus(id: string): Promise<InteractiveSessionStatus | null>;
1757
+ /**
1758
+ * @internal Test seam: unit tests replace this to intercept terminal
1759
+ * WebSocket dials without opening a real socket. Production paths always
1760
+ * go through `TerminalStream.connect`.
1761
+ */
1762
+ private _terminalStreamConnect;
1763
+ /**
1764
+ * Resolve a sandbox-relative terminal stream path against the browser-safe
1765
+ * sidecar proxy base returned by the scoped-token mint. Concatenation, not
1766
+ * URL resolution: the proxy base carries a path prefix
1767
+ * (`/v1/sidecar-proxy/{id}`) that `new URL(absolutePath, base)` would drop.
1768
+ */
1769
+ private resolveTerminalStreamUrl;
1770
+ /** @internal — invoked by InteractiveSessionHandle.attach(). */
1771
+ _attachInteractive(id: string, options?: InteractiveAttachOptions): Promise<TerminalStream>;
1772
+ /**
1773
+ * Per-dial credential for a terminal attach. The first dial consumes the
1774
+ * token minted alongside the proxy URL (no second mint); every later dial
1775
+ * (a `reconnect()` after the socket dropped or the detach window) re-mints,
1776
+ * because scoped terminal tokens are clamped to a <= 15-minute TTL and the
1777
+ * original is likely dead by then.
1778
+ */
1779
+ private terminalTokenProvider;
1780
+ /** @internal — invoked by `box.terminals.attach()`. */
1781
+ _attachTerminal(connectionId: string, options?: SandboxTerminalAttachOptions): Promise<TerminalStream>;
1546
1782
  /** @internal — invoked by InteractiveSessionHandle.stop(). */
1547
1783
  _stopInteractive(id: string): Promise<void>;
1548
1784
  /** @internal — invoked by SandboxSession.respondToPermission(). */
@@ -1567,4 +1803,4 @@ declare class SandboxInstance {
1567
1803
  }): Promise<DurablePlan>;
1568
1804
  }
1569
1805
  //#endregion
1570
- export { SandboxMcpConfig as C, buildSandboxMcpConfig as D, buildControlPlaneMcpConfig as E, SANDBOX_MCP_SERVER_NAME as S, SandboxMcpServerEntry as T, RespondToPermissionOptions as _, TraceExportSink as a, BuildSandboxMcpConfigOptions as b, otelTraceIdForTangleTrace as c, SandboxSession as d, InteractiveAuthFile as f, InterruptResult as g, InteractiveSessionInfo as h, TraceExportResult as i, toOtelJson as l, InteractiveSessionHost as m, SandboxInstance as n, buildTraceExportPayload as o, InteractiveSessionHandle as p, TraceExportFormat as r, exportTraceBundle as s, HttpClient as t, SandboxTaskSession as u, StartInteractiveOptions as v, SandboxMcpEndpoint as w, CONTROL_PLANE_MCP_SERVER_NAME as x, BuildControlPlaneMcpConfigOptions as y };
1806
+ export { SandboxMcpEndpoint as A, RespondToPermissionOptions as C, CONTROL_PLANE_MCP_SERVER_NAME as D, BuildSandboxMcpConfigOptions as E, buildControlPlaneMcpConfig as M, buildSandboxMcpConfig as N, SANDBOX_MCP_SERVER_NAME as O, InterruptResult as S, BuildControlPlaneMcpConfigOptions as T, InteractiveAuthFile as _, WorkspaceImagePublishResult as a, InteractiveSessionInfo as b, TraceExportResult as c, exportTraceBundle as d, otelTraceIdForTangleTrace as f, InteractiveAttachOptions as g, SandboxSession as h, WorkspaceImagePublishRequestOptions as i, SandboxMcpServerEntry as j, SandboxMcpConfig as k, TraceExportSink as l, SandboxTaskSession as m, SandboxInstance as n, WorkspaceImages as o, toOtelJson as p, WorkspaceImagePublishInput as r, TraceExportFormat as s, HttpClient as t, buildTraceExportPayload as u, InteractiveSessionHandle as v, StartInteractiveOptions as w, InteractiveSessionStatus as x, InteractiveSessionHost as y };