@tangle-network/sandbox 0.11.1 → 0.12.0-develop.20260724231304.911a687

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 SendSessionMessageOptions, Ar as SandboxResourceUsage, At as GitDiff, Bi as WriteFileOptions, Bn as RolloutStartResult, C as CodeExecutionResult, Ci as TaskSessionInfo, D as CommitTaskSessionOptions, Di as TeeAttestationResponse, Dr as SandboxPortBinding, Dt as GitBranch, Fn as ResumeOptions, Fr as SandboxStatus, G as DriveTurnOptions, Gn as SSHCredentials, Gr as SandboxTraceOptions, Gt as IntelligenceReportBudget, H as DispatchedSession, Hi as WriteManyOptions, Hr as SandboxTraceBundle, I as CreateSessionOptions, In as Rollout, Ir as SandboxTerminalAttachOptions, Jt as IntelligenceReportWindow, Kt as IntelligenceReportCompareTo, L as CreateTaskSessionOptions, Lt as GpuLeaseManager, Mr as SandboxRuntimeHealth, Mt as GpuLease, Ni as TurnDriveResult, O as CompletedTurnResult, Ot as GitCommit, Pn as RestoreSnapshotOptions, Pr as SandboxRuntimeProfileList, Ri as WaitForOptions, Rn as RolloutOptions, S as CodeExecutionOptions, Sn as ProvisionResult, Ti as TeeAttestationOptions, Ut as InstalledTool, V as DispatchPromptOptions, Vi as WriteManyFile, Vr as SandboxTerminals, Wn as SSHCommandDescriptor, Wt as IntelligenceReport, X as EgressManager, Xr as SearchOptions, Xt as ListMessagesOptions, Y as DurablePlan, Yn as SandboxEvent, Yr as SearchMatch, Yt as JsonValue, Zi as TerminalStream, ai as SessionInfo, bi as TaskSessionChanges, bn as PromptResult, di as SnapshotOptions, ea as TerminalStreamHandlers, ei as SendSessionMessageRequest, fi as SnapshotResult, ht as FileWriteResult, ii as SessionForkOptions, in as NetworkManager, jt as GitStatus, ki as TeePublicKeyResponse, l as BackendManager, ln as PreviewLinkManager, lt as FileSystem, mi as StartupDiagnostics, mn as ProcessManager, mr as SandboxFleetTraceBundle, nt as ExecResult, oi as SessionListOptions, q as DriverInfo, qn as SandboxConnection, qr as ScopedToken, ri as SessionEventStreamOptions, s as BackendConfig, si as SessionMessage, sn as PermissionsManager, ti as SentSessionMessage, tn as MintScopedTokenOptions, tt as ExecOptions, ui as SnapshotInfo, vi as TaskOptions, vn as PromptInputPart, w as CodeLanguage, wr as SandboxInfo, xi as TaskSessionCommitResult, xn as ProvisionEvent, y as BranchOptions, yi as TaskResult, yn as PromptOptions, zi as WaitForRolloutOptions } from "./types-BBocO2Ht.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,39 @@ 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 already holds `profile` under `sha256`, so
884
+ * subsequent turns whose profile serializes byte-identically send
885
+ * `backend.profileSha256` instead of the inline corpus. Use this to hydrate
886
+ * a freshly-fetched instance (`get()`/`list()`) from caller-persisted state
887
+ * — the reference otherwise lives only on the instance that primed it.
888
+ * Captures a content snapshot, so mutating the object afterwards is
889
+ * detected and that turn falls back to sending the profile inline.
890
+ */
891
+ attachProfileReference(profile: object, sha256: string): void;
892
+ /**
893
+ * Upload `profile` to the runtime once (`POST /agents/profiles`) and record
894
+ * the returned hash via {@link attachProfileReference}, so subsequent turns
895
+ * reference it by `profileSha256` instead of re-sending the corpus.
896
+ * `create()` calls this automatically for its inline profile when
897
+ * `autoDeferProfile` is on; call it directly when the profile only exists
898
+ * per-turn, or when the instance was fetched rather than created. Persist
899
+ * the returned sha256 alongside a content hash of the profile to
900
+ * re-attach on later instances without re-priming. Throws on transport/HTTP
901
+ * failure — the caller decides whether that is fatal (it is not: turns fall
902
+ * back to sending the full profile inline).
903
+ */
904
+ primeProfile(profile: object): Promise<string>;
905
+ /**
906
+ * Build the run request's `backend` body. When the outgoing profile's CONTENT
907
+ * matches the one the runtime already holds (and we are not resending after a
908
+ * cache miss), swap the inline `profile` for its `profileSha256` so a large
909
+ * static corpus does not ride every turn. The match is by serialized content,
910
+ * not object identity, so a mutated-in-place profile — or an equivalent
911
+ * object passed as a per-turn override — is compared correctly: unchanged
912
+ * content references by hash, changed content sends inline (the legacy shape).
913
+ */
914
+ private buildRunBackendBody;
711
915
  streamPrompt(message: string | PromptInputPart[], options?: PromptOptions): AsyncGenerator<SandboxEvent>;
712
916
  /**
713
917
  * Inner prompt stream: opens the SSE connection and reconnects on silent
@@ -818,8 +1022,12 @@ declare class SandboxInstance {
818
1022
  runtimeHealth(): Promise<SandboxRuntimeHealth>;
819
1023
  /** Return the runtime's current listening-port snapshot. */
820
1024
  ports(): Promise<SandboxPortBinding[]>;
821
- /** Interactive terminal operations for this runtime. */
822
- get terminals(): SandboxTerminalManager;
1025
+ /**
1026
+ * Interactive terminal operations for this runtime: the REST manager
1027
+ * (create/input/list/get) plus `attach()`, which opens the live terminal
1028
+ * WebSocket as a {@link TerminalStream}.
1029
+ */
1030
+ get terminals(): SandboxTerminals;
823
1031
  /** List profiles installed in this sandbox runtime. */
824
1032
  listProfiles(): Promise<SandboxRuntimeProfileList>;
825
1033
  /**
@@ -907,6 +1115,7 @@ declare class SandboxInstance {
907
1115
  get fs(): FileSystem;
908
1116
  private fsReadBatch;
909
1117
  private fsTree;
1118
+ private fsUsage;
910
1119
  private fsUpload;
911
1120
  /** See {@link FileSystem.uploadData}. Delegates to the shared, browser-safe
912
1121
  * chunked-upload flow in `lib/chunked-upload.ts`, wired to this sandbox's
@@ -1034,6 +1243,7 @@ declare class SandboxInstance {
1034
1243
  * ```
1035
1244
  */
1036
1245
  get process(): ProcessManager;
1246
+ private processEnsureDevServer;
1037
1247
  private processSpawn;
1038
1248
  private processSpawnExact;
1039
1249
  private processRunCode;
@@ -1339,6 +1549,10 @@ declare class SandboxInstance {
1339
1549
  /**
1340
1550
  * Wait for the sandbox to reach a specific status.
1341
1551
  *
1552
+ * A sandbox using the filesystem-incarnation contract is not considered
1553
+ * `running` until that incarnation is ready. Legacy servers that omit the
1554
+ * contract retain the status-only behavior.
1555
+ *
1342
1556
  * When `onProgress` is provided and the sandbox is still provisioning,
1343
1557
  * uses SSE events for real-time progress instead of polling. Falls back
1344
1558
  * to polling if the SSE connection fails or is unavailable.
@@ -1366,7 +1580,9 @@ declare class SandboxInstance {
1366
1580
  * delivers progress callbacks while waiting for a target status.
1367
1581
  */
1368
1582
  private waitForWithSSE;
1583
+ private hasReachedWaitTarget;
1369
1584
  private ensureRunning;
1585
+ private assertFilesystemIncarnationReady;
1370
1586
  private runtimeFetch;
1371
1587
  /**
1372
1588
  * Delegates to the shared `parseSSEStream` in `lib/sse-parser.ts`
@@ -1389,13 +1605,13 @@ declare class SandboxInstance {
1389
1605
  * ```typescript
1390
1606
  * await box.registerSessionMapping({
1391
1607
  * sessionId: "sess_abc",
1392
- * userId: "user_123",
1608
+ * runtimeSessionId: "runtime_abc",
1393
1609
  * });
1394
1610
  * ```
1395
1611
  */
1396
1612
  registerSessionMapping(opts: {
1397
- sessionId: string;
1398
- userId: string; /** The runtime (sidecar) session id this agent session routes to. */
1613
+ sessionId: string; /** @deprecated Ownership is derived from the Sandbox API key. */
1614
+ userId?: string; /** The runtime (sidecar) session id this agent session routes to. */
1399
1615
  runtimeSessionId: string; /** Optional container id for direct routing. */
1400
1616
  sidecarId?: string; /** Optional projectRef so the server can detect a stale sidecar. */
1401
1617
  projectRef?: string;
@@ -1406,8 +1622,8 @@ declare class SandboxInstance {
1406
1622
  * sandbox stays alive.
1407
1623
  */
1408
1624
  unregisterSessionMapping(opts: {
1409
- sessionId: string;
1410
- userId: string;
1625
+ sessionId: string; /** @deprecated Ownership is derived from the Sandbox API key. */
1626
+ userId?: string;
1411
1627
  }): Promise<{
1412
1628
  success: boolean;
1413
1629
  sessionId: string;
@@ -1530,7 +1746,7 @@ declare class SandboxInstance {
1530
1746
  /** @internal — invoked by SandboxSession.events(). */
1531
1747
  _sessionEvents(id: string, opts?: SessionEventStreamOptions, stopOnTurnTerminal?: boolean): AsyncGenerator<SandboxEvent>;
1532
1748
  /** @internal — invoked by SandboxSession.result(). */
1533
- _sessionResult(id: string): Promise<PromptResult>;
1749
+ _sessionResult(id: string, knownSession?: SessionInfo): Promise<PromptResult>;
1534
1750
  /**
1535
1751
  * @internal — invoked by SandboxSession.cancel(). Void-returning alias of
1536
1752
  * `_interrupt`: both abort the in-flight execution via `POST /{id}/abort`
@@ -1543,6 +1759,33 @@ declare class SandboxInstance {
1543
1759
  _startInteractive(id: string, options: StartInteractiveOptions): Promise<InteractiveSessionInfo>;
1544
1760
  /** @internal — invoked by InteractiveSessionHandle.sendPrompt(). */
1545
1761
  _sendInteractivePrompt(id: string, prompt: string): Promise<void>;
1762
+ /** @internal — invoked by InteractiveSessionHandle.status(). */
1763
+ _interactiveStatus(id: string): Promise<InteractiveSessionStatus | null>;
1764
+ /**
1765
+ * @internal Test seam: unit tests replace this to intercept terminal
1766
+ * WebSocket dials without opening a real socket. Production paths always
1767
+ * go through `TerminalStream.connect`.
1768
+ */
1769
+ private _terminalStreamConnect;
1770
+ /**
1771
+ * Resolve a sandbox-relative terminal stream path against the browser-safe
1772
+ * sidecar proxy base returned by the scoped-token mint. Concatenation, not
1773
+ * URL resolution: the proxy base carries a path prefix
1774
+ * (`/v1/sidecar-proxy/{id}`) that `new URL(absolutePath, base)` would drop.
1775
+ */
1776
+ private resolveTerminalStreamUrl;
1777
+ /** @internal — invoked by InteractiveSessionHandle.attach(). */
1778
+ _attachInteractive(id: string, options?: InteractiveAttachOptions): Promise<TerminalStream>;
1779
+ /**
1780
+ * Per-dial credential for a terminal attach. The first dial consumes the
1781
+ * token minted alongside the proxy URL (no second mint); every later dial
1782
+ * (a `reconnect()` after the socket dropped or the detach window) re-mints,
1783
+ * because scoped terminal tokens are clamped to a <= 15-minute TTL and the
1784
+ * original is likely dead by then.
1785
+ */
1786
+ private terminalTokenProvider;
1787
+ /** @internal — invoked by `box.terminals.attach()`. */
1788
+ _attachTerminal(connectionId: string, options?: SandboxTerminalAttachOptions): Promise<TerminalStream>;
1546
1789
  /** @internal — invoked by InteractiveSessionHandle.stop(). */
1547
1790
  _stopInteractive(id: string): Promise<void>;
1548
1791
  /** @internal — invoked by SandboxSession.respondToPermission(). */
@@ -1567,4 +1810,4 @@ declare class SandboxInstance {
1567
1810
  }): Promise<DurablePlan>;
1568
1811
  }
1569
1812
  //#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 };
1813
+ 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 };