@cloudflare/sandbox 0.10.0 → 0.10.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.
@@ -24,21 +24,29 @@ interface DesktopProcessHealth {
24
24
  uptime?: number;
25
25
  }
26
26
  type DesktopImageFormat = 'png' | 'jpeg' | 'webp';
27
- interface DesktopScreenshotRequest {
28
- format?: 'base64';
27
+ interface DesktopScreenshotOptions {
28
+ /**
29
+ * How the SDK returns the screenshot payload to the caller.
30
+ * - `'base64'` (default): `data` is a base64-encoded string (also the wire format).
31
+ * - `'bytes'`: client-side convenience that base64-decodes the wire payload
32
+ * into a `Uint8Array` before returning. The wire/server contract is
33
+ * always base64.
34
+ */
35
+ format?: 'base64' | 'bytes';
29
36
  imageFormat?: DesktopImageFormat;
30
37
  quality?: number;
31
38
  showCursor?: boolean;
32
39
  }
33
- interface DesktopScreenshotRegionRequest extends DesktopScreenshotRequest {
34
- region: DesktopScreenshotRegion;
35
- }
36
40
  interface DesktopScreenshotRegion {
37
41
  x: number;
38
42
  y: number;
39
43
  width: number;
40
44
  height: number;
41
45
  }
46
+ /**
47
+ * Screenshot payload returned to the SDK caller when `format` is `'base64'`
48
+ * (the default). Matches the wire shape sent by the container.
49
+ */
42
50
  interface DesktopScreenshotResult {
43
51
  success: boolean;
44
52
  data: string;
@@ -46,6 +54,14 @@ interface DesktopScreenshotResult {
46
54
  width: number;
47
55
  height: number;
48
56
  }
57
+ /**
58
+ * Screenshot payload returned to the SDK caller when `format: 'bytes'` is
59
+ * requested. The SDK client decodes the base64 wire payload into a
60
+ * `Uint8Array`; the server/wire contract is unchanged.
61
+ */
62
+ interface DesktopScreenshotBytesResult extends Omit<DesktopScreenshotResult, 'data'> {
63
+ data: Uint8Array;
64
+ }
49
65
  type DesktopMouseButton = 'left' | 'right' | 'middle';
50
66
  type DesktopScrollDirection = 'up' | 'down' | 'left' | 'right';
51
67
  interface DesktopCursorPosition {
@@ -859,6 +875,15 @@ interface WriteFileResult {
859
875
  timestamp: string;
860
876
  exitCode?: number;
861
877
  }
878
+ /**
879
+ * Valid `encoding` values accepted by `readFile` / `writeFile` options.
880
+ *
881
+ * - `'utf-8'` / `'utf8'` — treat content as text.
882
+ * - `'base64'` — treat content as base64-encoded binary.
883
+ * - `'none'` — RPC-only streaming variant of `readFile`, returns a
884
+ * `ReadableStream<Uint8Array>` of raw bytes (see `ReadFileStreamResult`).
885
+ */
886
+ type FileEncoding = 'utf-8' | 'utf8' | 'base64' | 'none';
862
887
  interface ReadFileResult {
863
888
  success: boolean;
864
889
  path: string;
@@ -882,6 +907,21 @@ interface ReadFileResult {
882
907
  */
883
908
  size?: number;
884
909
  }
910
+ /**
911
+ * Result of `readFile()` with `encoding: 'none'` on the RPC transport.
912
+ *
913
+ * `content` is a raw binary `ReadableStream<Uint8Array>` delivered directly
914
+ * over the capnp channel — no base64 encoding, no SSE framing, no buffering.
915
+ * Only supported on the `rpc` transport; HTTP/WebSocket transports throw.
916
+ */
917
+ interface ReadFileStreamResult {
918
+ success: true;
919
+ path: string;
920
+ content: ReadableStream<Uint8Array>;
921
+ size: number;
922
+ mimeType: string;
923
+ timestamp: string;
924
+ }
885
925
  interface DeleteFileResult {
886
926
  success: boolean;
887
927
  path: string;
@@ -1172,8 +1212,11 @@ interface ExecutionSession {
1172
1212
  writeFile(path: string, content: string | ReadableStream<Uint8Array>, options?: {
1173
1213
  encoding?: string;
1174
1214
  }): Promise<WriteFileResult>;
1215
+ readFile(path: string, options: {
1216
+ encoding: 'none';
1217
+ }): Promise<ReadFileStreamResult>;
1175
1218
  readFile(path: string, options?: {
1176
- encoding?: string;
1219
+ encoding?: Exclude<FileEncoding, 'none'>;
1177
1220
  }): Promise<ReadFileResult>;
1178
1221
  readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;
1179
1222
  watch(path: string, options?: Omit<WatchOptions, 'sessionId'>): Promise<ReadableStream<Uint8Array>>;
@@ -1365,9 +1408,36 @@ interface LocalMountBucketOptions {
1365
1408
  readOnly?: boolean;
1366
1409
  }
1367
1410
  /**
1368
- * Options for mounting a bucket either remote (s3fs-FUSE) or local (R2 binding sync)
1411
+ * Options for mounting an R2 binding via credential-less egress interception.
1369
1412
  */
1370
- type MountBucketOptions = RemoteMountBucketOptions | LocalMountBucketOptions;
1413
+ interface R2BindingMountBucketOptions {
1414
+ /**
1415
+ * Must not be set — distinguishes this variant from RemoteMountBucketOptions.
1416
+ */
1417
+ endpoint?: never;
1418
+ /**
1419
+ * Optional prefix/subdirectory within the bucket to mount.
1420
+ *
1421
+ * When specified, only the contents under this prefix will be visible
1422
+ * at the mount point.
1423
+ */
1424
+ prefix?: string;
1425
+ /**
1426
+ * Mount filesystem as read-only
1427
+ * Default: false
1428
+ */
1429
+ readOnly?: boolean;
1430
+ /**
1431
+ * Advanced: Override or extend s3fs options.
1432
+ * Provider defaults for R2 are still applied automatically.
1433
+ */
1434
+ s3fsOptions?: string[];
1435
+ }
1436
+ /**
1437
+ * Options for mounting a bucket — remote (s3fs-FUSE), local (R2 binding sync),
1438
+ * or R2 egress (credential-less s3fs via egress interception).
1439
+ */
1440
+ type MountBucketOptions = RemoteMountBucketOptions | LocalMountBucketOptions | R2BindingMountBucketOptions;
1371
1441
  interface ISandbox {
1372
1442
  exec(command: string, options?: ExecOptions): Promise<ExecResult>;
1373
1443
  startProcess(command: string, options?: ProcessOptions): Promise<Process>;
@@ -1388,8 +1458,11 @@ interface ISandbox {
1388
1458
  writeFile(path: string, content: string | ReadableStream<Uint8Array>, options?: {
1389
1459
  encoding?: string;
1390
1460
  }): Promise<WriteFileResult>;
1461
+ readFile(path: string, options: {
1462
+ encoding: 'none';
1463
+ }): Promise<ReadFileStreamResult>;
1391
1464
  readFile(path: string, options?: {
1392
- encoding?: string;
1465
+ encoding?: Exclude<FileEncoding, 'none'>;
1393
1466
  }): Promise<ReadFileResult>;
1394
1467
  readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;
1395
1468
  watch(path: string, options?: WatchOptions): Promise<ReadableStream<Uint8Array>>;
@@ -1571,8 +1644,11 @@ interface SandboxCommandsAPI {
1571
1644
  }): Promise<ReadableStream<Uint8Array>>;
1572
1645
  }
1573
1646
  interface SandboxFilesAPI {
1647
+ readFile(path: string, sessionId: string, options: {
1648
+ encoding: 'none';
1649
+ }): Promise<ReadFileStreamResult>;
1574
1650
  readFile(path: string, sessionId: string, options?: {
1575
- encoding?: string;
1651
+ encoding?: Exclude<FileEncoding, 'none'>;
1576
1652
  }): Promise<ReadFileResult>;
1577
1653
  readFileStream(path: string, sessionId: string): Promise<ReadableStream<Uint8Array>>;
1578
1654
  writeFile(path: string, content: string, sessionId: string, options?: {
@@ -1681,8 +1757,20 @@ interface SandboxDesktopAPI {
1681
1757
  }): Promise<DesktopStartResult>;
1682
1758
  stop(): Promise<DesktopStopResult>;
1683
1759
  status(): Promise<DesktopStatusResult>;
1684
- screenshot(options?: DesktopScreenshotRequest): Promise<DesktopScreenshotResult>;
1685
- screenshotRegion(request: DesktopScreenshotRegionRequest): Promise<DesktopScreenshotResult>;
1760
+ screenshot(options?: DesktopScreenshotOptions & {
1761
+ format?: 'base64';
1762
+ }): Promise<DesktopScreenshotResult>;
1763
+ screenshot(options: DesktopScreenshotOptions & {
1764
+ format: 'bytes';
1765
+ }): Promise<DesktopScreenshotBytesResult>;
1766
+ screenshot(options?: DesktopScreenshotOptions): Promise<DesktopScreenshotResult | DesktopScreenshotBytesResult>;
1767
+ screenshotRegion(region: DesktopScreenshotRegion, options?: DesktopScreenshotOptions & {
1768
+ format?: 'base64';
1769
+ }): Promise<DesktopScreenshotResult>;
1770
+ screenshotRegion(region: DesktopScreenshotRegion, options: DesktopScreenshotOptions & {
1771
+ format: 'bytes';
1772
+ }): Promise<DesktopScreenshotBytesResult>;
1773
+ screenshotRegion(region: DesktopScreenshotRegion, options?: DesktopScreenshotOptions): Promise<DesktopScreenshotResult | DesktopScreenshotBytesResult>;
1686
1774
  click(x: number, y: number, options?: {
1687
1775
  button?: DesktopMouseButton;
1688
1776
  clickCount?: number;
@@ -1704,18 +1792,47 @@ interface SandboxDesktopAPI {
1704
1792
  scroll(x: number, y: number, direction: DesktopScrollDirection, amount?: number): Promise<void>;
1705
1793
  getCursorPosition(): Promise<DesktopCursorPosition>;
1706
1794
  type(text: string, options?: {
1707
- delay?: number;
1795
+ delayMs?: number;
1708
1796
  }): Promise<void>;
1709
1797
  press(key: string): Promise<void>;
1710
1798
  keyDown(key: string): Promise<void>;
1711
1799
  keyUp(key: string): Promise<void>;
1712
1800
  getScreenSize(): Promise<DesktopScreenSize>;
1713
- getProcessStatus(name: string): Promise<DesktopStatusResult>;
1801
+ getProcessStatus(name: string): Promise<DesktopProcessHealth>;
1714
1802
  }
1715
1803
  interface SandboxWatchAPI {
1716
1804
  watch(request: WatchRequest): Promise<ReadableStream<Uint8Array>>;
1717
1805
  checkChanges(request: CheckChangesRequest): Promise<CheckChangesResult>;
1718
1806
  }
1807
+ /**
1808
+ * Public-facing tunnel record.
1809
+ *
1810
+ * Today only quick tunnels (`*.trycloudflare.com`) are supported. Future
1811
+ * PRs will add named tunnels, which will carry a `name: string` field;
1812
+ * `TunnelInfo` will then become a discriminated union keyed on the
1813
+ * presence of `name`. The quick variant declares `name?: never` so the
1814
+ * narrowing works without a breaking change here.
1815
+ */
1816
+ interface TunnelInfo {
1817
+ id: string;
1818
+ port: number;
1819
+ url: string;
1820
+ hostname: string;
1821
+ createdAt: string;
1822
+ /** Reserved for the named-tunnel variant in a future PR. */
1823
+ name?: never;
1824
+ }
1825
+ interface SandboxTunnelsAPI {
1826
+ /** Spawn `cloudflared tunnel --url`. No credentials required. */
1827
+ runQuickTunnel(id: string, port: number): Promise<TunnelInfo>;
1828
+ /** Stop the cloudflared process for the given tunnel id. */
1829
+ destroyTunnel(id: string): Promise<{
1830
+ success: true;
1831
+ id: string;
1832
+ }>;
1833
+ /** List tunnels currently running inside the container. */
1834
+ listTunnels(): Promise<TunnelInfo[]>;
1835
+ }
1719
1836
  //#endregion
1720
1837
  //#region src/clients/types.d.ts
1721
1838
  /**
@@ -1922,7 +2039,7 @@ declare abstract class BaseHttpClient {
1922
2039
  * The container creates/extracts squashfs archives locally.
1923
2040
  * R2 upload/download is handled by the Sandbox DO, not by this client.
1924
2041
  */
1925
- declare class BackupClient extends BaseHttpClient {
2042
+ declare class BackupClient extends BaseHttpClient implements SandboxBackupAPI {
1926
2043
  /**
1927
2044
  * Tell the container to create a squashfs archive from a directory.
1928
2045
  * @param dir - Directory to back up
@@ -1957,7 +2074,7 @@ interface ExecuteResponse extends BaseApiResponse {
1957
2074
  /**
1958
2075
  * Client for command execution operations
1959
2076
  */
1960
- declare class CommandClient extends BaseHttpClient {
2077
+ declare class CommandClient extends BaseHttpClient implements SandboxCommandsAPI {
1961
2078
  /**
1962
2079
  * Execute a command and return the complete result
1963
2080
  * @param command - The command to execute
@@ -2085,16 +2202,12 @@ interface Desktop {
2085
2202
  keyDown(key: KeyInput): Promise<void>;
2086
2203
  keyUp(key: KeyInput): Promise<void>;
2087
2204
  getScreenSize(): Promise<ScreenSizeResponse>;
2088
- getProcessStatus(name: string): Promise<BaseApiResponse & {
2089
- running: boolean;
2090
- pid?: number;
2091
- uptime?: number;
2092
- }>;
2205
+ getProcessStatus(name: string): Promise<DesktopProcessHealth>;
2093
2206
  }
2094
2207
  /**
2095
2208
  * Client for desktop environment lifecycle, input, and screen operations
2096
2209
  */
2097
- declare class DesktopClient extends BaseHttpClient {
2210
+ declare class DesktopClient extends BaseHttpClient implements SandboxDesktopAPI {
2098
2211
  /**
2099
2212
  * Start the desktop environment with optional resolution and DPI.
2100
2213
  */
@@ -2198,11 +2311,7 @@ declare class DesktopClient extends BaseHttpClient {
2198
2311
  /**
2199
2312
  * Get health status for a specific desktop process.
2200
2313
  */
2201
- getProcessStatus(name: string): Promise<BaseApiResponse & {
2202
- running: boolean;
2203
- pid?: number;
2204
- uptime?: number;
2205
- }>;
2314
+ getProcessStatus(name: string): Promise<DesktopProcessHealth>;
2206
2315
  }
2207
2316
  //#endregion
2208
2317
  //#region src/clients/file-client.d.ts
@@ -2238,7 +2347,7 @@ interface FileOperationRequest extends SessionRequest {
2238
2347
  /**
2239
2348
  * Client for file system operations
2240
2349
  */
2241
- declare class FileClient extends BaseHttpClient {
2350
+ declare class FileClient extends BaseHttpClient implements SandboxFilesAPI {
2242
2351
  /**
2243
2352
  * Create a directory
2244
2353
  * @param path - Directory path to create
@@ -2259,13 +2368,21 @@ declare class FileClient extends BaseHttpClient {
2259
2368
  encoding?: string;
2260
2369
  }): Promise<WriteFileResult>;
2261
2370
  /**
2262
- * Read content from a file
2371
+ * Read content from a file.
2372
+ *
2263
2373
  * @param path - File path to read from
2264
2374
  * @param sessionId - The session ID for this operation
2265
2375
  * @param options - Optional settings (encoding)
2376
+ *
2377
+ * When `encoding` is `'none'`, returns a `ReadFileStreamResult` whose
2378
+ * `content` is a raw `ReadableStream<Uint8Array>`. This variant only works
2379
+ * on the `rpc` transport; HTTP and WebSocket transports throw at runtime.
2266
2380
  */
2381
+ readFile(path: string, sessionId: string, options: {
2382
+ encoding: 'none';
2383
+ }): Promise<ReadFileStreamResult>;
2267
2384
  readFile(path: string, sessionId: string, options?: {
2268
- encoding?: string;
2385
+ encoding?: Exclude<FileEncoding, 'none'>;
2269
2386
  }): Promise<ReadFileResult>;
2270
2387
  /**
2271
2388
  * Stream a file using Server-Sent Events
@@ -2307,6 +2424,16 @@ declare class FileClient extends BaseHttpClient {
2307
2424
  * @param sessionId - The session ID for this operation
2308
2425
  */
2309
2426
  exists(path: string, sessionId: string): Promise<FileExistsResult>;
2427
+ /**
2428
+ * Write a file via a raw binary stream over the RPC transport.
2429
+ * Throws on HTTP and WebSocket transports — use writeFile() with a string instead.
2430
+ */
2431
+ writeFileStream(_path: string, _content: ReadableStream<Uint8Array>, _sessionId: string): Promise<{
2432
+ success: boolean;
2433
+ path: string;
2434
+ bytesWritten: number;
2435
+ timestamp: string;
2436
+ }>;
2310
2437
  }
2311
2438
  //#endregion
2312
2439
  //#region src/clients/git-client.d.ts
@@ -2325,7 +2452,7 @@ interface GitCheckoutRequest extends SessionRequest {
2325
2452
  /**
2326
2453
  * Client for Git repository operations
2327
2454
  */
2328
- declare class GitClient extends BaseHttpClient {
2455
+ declare class GitClient extends BaseHttpClient implements SandboxGitAPI {
2329
2456
  private static readonly REQUEST_TIMEOUT_BUFFER_MS;
2330
2457
  constructor(options?: HttpClientOptions);
2331
2458
  /**
@@ -2351,7 +2478,7 @@ interface ExecutionCallbacks {
2351
2478
  onResult?: (result: Result) => void | Promise<void>;
2352
2479
  onError?: (error: ExecutionError) => void | Promise<void>;
2353
2480
  }
2354
- declare class InterpreterClient extends BaseHttpClient {
2481
+ declare class InterpreterClient extends BaseHttpClient implements SandboxInterpreterAPI {
2355
2482
  private readonly maxRetries;
2356
2483
  private readonly retryDelayMs;
2357
2484
  createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
@@ -2383,7 +2510,7 @@ interface UnexposePortRequest {
2383
2510
  /**
2384
2511
  * Client for port management and preview URL operations
2385
2512
  */
2386
- declare class PortClient extends BaseHttpClient {
2513
+ declare class PortClient extends BaseHttpClient implements SandboxPortsAPI {
2387
2514
  /**
2388
2515
  * Expose a port and get a preview URL
2389
2516
  * @param port - Port number to expose
@@ -2414,7 +2541,7 @@ declare class PortClient extends BaseHttpClient {
2414
2541
  /**
2415
2542
  * Client for background process management
2416
2543
  */
2417
- declare class ProcessClient extends BaseHttpClient {
2544
+ declare class ProcessClient extends BaseHttpClient implements SandboxProcessesAPI {
2418
2545
  /**
2419
2546
  * Start a background process
2420
2547
  * @param command - Command to execute as a background process
@@ -2511,7 +2638,7 @@ interface DeleteSessionResponse extends BaseApiResponse {
2511
2638
  /**
2512
2639
  * Client for health checks and utility operations
2513
2640
  */
2514
- declare class UtilityClient extends BaseHttpClient {
2641
+ declare class UtilityClient extends BaseHttpClient implements SandboxUtilsAPI {
2515
2642
  /**
2516
2643
  * Ping the sandbox to check if it's responsive
2517
2644
  */
@@ -2535,6 +2662,9 @@ declare class UtilityClient extends BaseHttpClient {
2535
2662
  * Returns the version embedded in the Docker image during build
2536
2663
  */
2537
2664
  getVersion(): Promise<string>;
2665
+ listSessions(): Promise<{
2666
+ sessions: string[];
2667
+ }>;
2538
2668
  }
2539
2669
  //#endregion
2540
2670
  //#region src/clients/watch-client.d.ts
@@ -2545,7 +2675,7 @@ declare class UtilityClient extends BaseHttpClient {
2545
2675
  * @internal This client is used internally by the SDK.
2546
2676
  * Users should use `sandbox.watch()` or `sandbox.checkChanges()` instead.
2547
2677
  */
2548
- declare class WatchClient extends BaseHttpClient {
2678
+ declare class WatchClient extends BaseHttpClient implements SandboxWatchAPI {
2549
2679
  /**
2550
2680
  * Check whether a path changed since a previously returned version.
2551
2681
  */
@@ -2589,6 +2719,13 @@ declare class SandboxClient {
2589
2719
  readonly utils: UtilityClient;
2590
2720
  readonly desktop: DesktopClient;
2591
2721
  readonly watch: WatchClient;
2722
+ /**
2723
+ * Tunnels are RPC-only — the route-based transport does not implement them.
2724
+ * This getter exists so the `PublicKeys<SandboxClient> satisfies
2725
+ * PublicKeys<SandboxAPI>` compile-time check holds. Calling any method on
2726
+ * the returned proxy throws a clear `RPC transport required` error.
2727
+ */
2728
+ readonly tunnels: never;
2592
2729
  private transport;
2593
2730
  constructor(options: HttpClientOptions);
2594
2731
  /**
@@ -2607,19 +2744,6 @@ declare class SandboxClient {
2607
2744
  * Check if WebSocket is connected (only relevant in WebSocket mode)
2608
2745
  */
2609
2746
  isWebSocketConnected(): boolean;
2610
- /**
2611
- * Stream a file directly to the container over a binary RPC channel.
2612
- *
2613
- * Requires the container-control path (`transport: 'rpc'`). Calling this
2614
- * method with the HTTP or WebSocket route transports throws an error because
2615
- * those transports do not support binary streaming.
2616
- */
2617
- writeFileStream(_path: string, _content: ReadableStream<Uint8Array>, _sessionId: string): Promise<{
2618
- success: boolean;
2619
- path: string;
2620
- bytesWritten: number;
2621
- timestamp: string;
2622
- }>;
2623
2747
  /**
2624
2748
  * Connect WebSocket transport (no-op in HTTP mode)
2625
2749
  * Called automatically on first request, but can be called explicitly
@@ -2648,6 +2772,25 @@ interface ContainerControlConnectionOptions {
2648
2772
  * `WebSocketTransport`. Set to 0 to disable retries.
2649
2773
  */
2650
2774
  retryTimeoutMs?: number;
2775
+ /**
2776
+ * Optional `localMain` exposed to the container side of the capnweb
2777
+ * session. The container reaches it via
2778
+ * `session.getRemoteMain()` and uses it for control-plane callbacks
2779
+ * (e.g. notifying the DO when a tunnel's cloudflared process has
2780
+ * exited). When omitted, the container sees an empty remote main.
2781
+ */
2782
+ localMain?: any;
2783
+ /**
2784
+ * Invoked when an active WebSocket transitions to closed/errored.
2785
+ * Fired at most once per successful connection from the WS event
2786
+ * handlers in `doConnect`. Gives owners a synchronous teardown
2787
+ * signal so recovery doesn't depend on a periodic poller running
2788
+ * inside what may be an idle isolate.
2789
+ *
2790
+ * Not fired for `doConnect` failures (the rejected `connect()`
2791
+ * promise is the signal in that case) nor for `disconnect()`.
2792
+ */
2793
+ onClose?: () => void;
2651
2794
  }
2652
2795
  //#endregion
2653
2796
  //#region src/container-control/client.d.ts
@@ -2704,13 +2847,6 @@ declare class ContainerControlClient {
2704
2847
  private busyPollTimer;
2705
2848
  /** Tracks whether we currently believe the session is busy. */
2706
2849
  private busy;
2707
- /**
2708
- * Set the first time the poller observes `conn.isConnected() === true`,
2709
- * cleared in `destroyConnection()`. Lets us distinguish "the WebSocket
2710
- * upgrade is still in progress" (don't tear down) from "we were
2711
- * connected and the peer went away" (do tear down).
2712
- */
2713
- private wasEverConnected;
2714
2850
  constructor(options: ContainerControlClientOptions);
2715
2851
  /**
2716
2852
  * Return the current connection, creating one when the client is disconnected.
@@ -2749,6 +2885,7 @@ declare class ContainerControlClient {
2749
2885
  get backup(): SandboxBackupAPI;
2750
2886
  get desktop(): SandboxDesktopAPI;
2751
2887
  get watch(): SandboxWatchAPI;
2888
+ get tunnels(): SandboxTunnelsAPI;
2752
2889
  get interpreter(): SandboxInterpreterAPI;
2753
2890
  /**
2754
2891
  * Update the 503 upgrade-retry budget. Applies to the current connection
@@ -2760,12 +2897,13 @@ declare class ContainerControlClient {
2760
2897
  isWebSocketConnected(): boolean;
2761
2898
  connect(): Promise<void>;
2762
2899
  disconnect(): void;
2763
- writeFileStream(path: string, stream: ReadableStream<Uint8Array>, sessionId: string): Promise<{
2764
- success: boolean;
2765
- path: string;
2766
- bytesWritten: number;
2767
- timestamp: string;
2768
- }>;
2900
+ }
2901
+ //#endregion
2902
+ //#region src/tunnels/tunnels-handler.d.ts
2903
+ interface TunnelsHandler {
2904
+ get(port: number): Promise<TunnelInfo>;
2905
+ list(): Promise<TunnelInfo[]>;
2906
+ destroy(portOrInfo: number | TunnelInfo): Promise<void>;
2769
2907
  }
2770
2908
  //#endregion
2771
2909
  //#region src/sandbox.d.ts
@@ -2786,6 +2924,9 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
2786
2924
  client: SandboxClient | ContainerControlClient;
2787
2925
  private codeInterpreter;
2788
2926
  private sandboxName;
2927
+ private tunnelsHandler;
2928
+ private tunnelExitHandler;
2929
+ private readonly controlCallback;
2789
2930
  private normalizeId;
2790
2931
  private defaultSession;
2791
2932
  private containerGeneration;
@@ -2855,9 +2996,16 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
2855
2996
  * Dispatch method for desktop operations.
2856
2997
  * Called by the client-side proxy created in getSandbox() to provide
2857
2998
  * the `sandbox.desktop.status()` API without relying on RPC pipelining
2858
- * through property getters.
2999
+ * through property getters which is broken when using vite-plugin.
2859
3000
  */
2860
3001
  callDesktop(method: string, args: unknown[]): Promise<unknown>;
3002
+ /**
3003
+ * Dispatch method for tunnel operations.
3004
+ * Called by the client-side proxy created in getSandbox() to provide
3005
+ * the `sandbox.tunnels` API without relying on RPC pipelining
3006
+ * through property getters which is broken when using vite-plugin.
3007
+ */
3008
+ callTunnels(method: string, args: unknown[]): Promise<unknown>;
2861
3009
  /**
2862
3010
  * Compute the transport retry budget from current container timeouts.
2863
3011
  *
@@ -2927,6 +3075,13 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
2927
3075
  * Local dev mount: bidirectional sync via R2 binding + file/watch APIs
2928
3076
  */
2929
3077
  private mountBucketLocal;
3078
+ private getR2EgressParams;
3079
+ private validateR2EgressS3fsOptions;
3080
+ /**
3081
+ * Credential-less R2 mount: egress interception routes s3fs requests to the
3082
+ * R2 binding. No S3 credentials are needed in the container or Worker env.
3083
+ */
3084
+ private mountBucketR2Egress;
2930
3085
  /**
2931
3086
  * Production mount: S3FS-FUSE inside the container
2932
3087
  */
@@ -2939,7 +3094,11 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
2939
3094
  */
2940
3095
  unmountBucket(mountPath: string): Promise<void>;
2941
3096
  /**
2942
- * Validate mount options
3097
+ * Shared validation for mount path (absolute, not already in use).
3098
+ */
3099
+ private validateMountPath;
3100
+ /**
3101
+ * Validate mount options for remote (FUSE) mounts
2943
3102
  */
2944
3103
  private validateMountOptions;
2945
3104
  /**
@@ -2959,6 +3118,7 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
2959
3118
  * Execute S3FS mount command
2960
3119
  */
2961
3120
  private executeS3FSMount;
3121
+ private unmountTrackedFuseMount;
2962
3122
  /**
2963
3123
  * In-flight `destroy()` promise. While set, concurrent callers coalesce
2964
3124
  * onto the same teardown instead of triggering a second one. Cleared when
@@ -3184,8 +3344,22 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
3184
3344
  deleteFile(path: string, sessionId?: string): Promise<DeleteFileResult>;
3185
3345
  renameFile(oldPath: string, newPath: string, sessionId?: string): Promise<RenameFileResult>;
3186
3346
  moveFile(sourcePath: string, destinationPath: string, sessionId?: string): Promise<MoveFileResult>;
3347
+ /**
3348
+ * Read a file from the sandbox.
3349
+ *
3350
+ * @param encoding - How to encode the returned content:
3351
+ * - `undefined` (default): auto-detect from MIME type (text → UTF-8 string, binary → base64 string)
3352
+ * - `'utf-8'` / `'utf8'`: always return as UTF-8 string
3353
+ * - `'base64'`: always return as base64-encoded string
3354
+ * - `'none'`: return a result whose `content` is a raw binary `ReadableStream<Uint8Array>`
3355
+ * with no encoding overhead. **Requires `SANDBOX_TRANSPORT=rpc`.** Throws on HTTP/WebSocket transports.
3356
+ */
3357
+ readFile(path: string, options: {
3358
+ encoding: 'none';
3359
+ sessionId?: string;
3360
+ }): Promise<ReadFileStreamResult>;
3187
3361
  readFile(path: string, options?: {
3188
- encoding?: string;
3362
+ encoding?: Exclude<FileEncoding, 'none'>;
3189
3363
  sessionId?: string;
3190
3364
  }): Promise<ReadFileResult>;
3191
3365
  /**
@@ -3289,6 +3463,33 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
3289
3463
  port: number;
3290
3464
  status: "active" | "inactive";
3291
3465
  }[]>;
3466
+ /**
3467
+ * Namespaced tunnel API. Quick tunnels are zero-config preview URLs
3468
+ * backed by Cloudflare's trycloudflare service.
3469
+ *
3470
+ * - `tunnels.get(port)` — idempotent. Returns the cached tunnel for
3471
+ * `port` if one exists in DO storage, otherwise spawns a fresh
3472
+ * cloudflared process and persists the record.
3473
+ * - `tunnels.list()` — records currently known to this sandbox, from
3474
+ * DO storage.
3475
+ * - `tunnels.destroy(portOrInfo)` — tear down by port number or by
3476
+ * the record returned from `get()`.
3477
+ *
3478
+ * Storage is cleared on container restart (`onStart`), so URLs do
3479
+ * not survive a container restart — the next `get(port)` call will
3480
+ * spawn a fresh tunnel with a new URL.
3481
+ *
3482
+ * Requires the RPC transport. Calling this on a route-based transport
3483
+ * throws "RPC transport required".
3484
+ */
3485
+ get tunnels(): TunnelsHandler;
3486
+ /**
3487
+ * Lazily construct both the public tunnels handler and its sibling
3488
+ * exit-handler callback. Called from the `tunnels` getter on first
3489
+ * access and on every access after a transport swap clears both
3490
+ * fields.
3491
+ */
3492
+ private ensureTunnelsBuilt;
3292
3493
  isPortExposed(port: number): Promise<boolean>;
3293
3494
  validatePortToken(port: number, token: string): Promise<boolean>;
3294
3495
  private validateCustomToken;
@@ -3481,7 +3682,8 @@ declare class Sandbox<Env = unknown> extends Container<Env> implements ISandbox
3481
3682
  * unsquashfs for extraction instead of squashfuse + fuse-overlayfs.
3482
3683
  */
3483
3684
  private doRestoreBackupLocal;
3685
+ private configureR2EgressOutbound;
3484
3686
  }
3485
3687
  //#endregion
3486
- export { BackupOptions as $, DesktopStopResponse as A, ProcessStartResult as At, ExecuteResponse as B, WatchOptions as Bt, ClickOptions as C, Process as Ct, DesktopStartOptions as D, ProcessListResult as Dt, DesktopClient as E, ProcessKillResult as Et, ScreenshotRegion as F, SandboxTransport as Ft, HttpClientOptions as G, CodeContext as Gt, BaseApiResponse as H, isProcess as Ht, ScreenshotResponse as I, SessionOptions as It, SessionRequest as J, ExecutionResult as Jt, RequestConfig as K, CreateContextOptions as Kt, ScrollDirection as L, StreamOptions as Lt, ScreenSizeResponse as M, RemoteMountBucketOptions as Mt, ScreenshotBytesResponse as N, RestoreBackupResult as Nt, DesktopStartResponse as O, ProcessLogsResult as Ot, ScreenshotOptions as P, SandboxOptions as Pt, StartProcessRequest as Q, TypeOptions as R, WaitForLogResult as Rt, WriteFileRequest as S, PortListResult as St, Desktop as T, ProcessInfoResult as Tt, ContainerStub as U, isProcessStatus as Ut, BackupClient as V, isExecResult as Vt, ErrorResponse as W, PtyOptions as Wt, ExecuteRequest as X, SandboxInterpreterAPI as Y, RunCodeOptions as Yt, ExposePortRequest as Z, GitClient as _, LocalMountBucketOptions as _t, CreateSessionRequest as a, DirectoryBackup as at, MkdirRequest as b, PortCloseResult as bt, DeleteSessionResponse as c, ExecResult as ct, ProcessClient as d, FileMetadata as dt, BaseExecOptions as et, PortClient as f, FileStreamEvent as ft, GitCheckoutRequest as g, ListFilesOptions as gt, InterpreterClient as h, ISandbox as ht, CommandsResponse as i, CheckChangesResult as it, KeyInput as j, ProcessStatus as jt, DesktopStatusResponse as k, ProcessOptions as kt, PingResponse as l, ExecutionSession as lt, ExecutionCallbacks as m, GitCheckoutResult as mt, getSandbox as n, BucketProvider as nt, CreateSessionResponse as o, ExecEvent as ot, UnexposePortRequest as p, FileWatchSSEEvent as pt, ResponseHandler as q, Execution as qt, SandboxClient as r, CheckChangesOptions as rt, DeleteSessionRequest as s, ExecOptions as st, Sandbox as t, BucketCredentials as tt, UtilityClient as u, FileChunk as ut, FileClient as v, LogEvent as vt, CursorPositionResponse as w, ProcessCleanupResult as wt, ReadFileRequest as x, PortExposeResult as xt, FileOperationRequest as y, MountBucketOptions as yt, CommandClient as z, WaitForPortOptions as zt };
3487
- //# sourceMappingURL=sandbox-C-AzrX_L.d.ts.map
3688
+ export { StartProcessRequest as $, DesktopStopResponse as A, ProcessOptions as At, ExecuteResponse as B, WaitForPortOptions as Bt, ClickOptions as C, PortListResult as Ct, DesktopStartOptions as D, ProcessKillResult as Dt, DesktopClient as E, ProcessInfoResult as Et, ScreenshotRegion as F, SandboxOptions as Ft, HttpClientOptions as G, PtyOptions as Gt, BaseApiResponse as H, isExecResult as Ht, ScreenshotResponse as I, SandboxTransport as It, SessionRequest as J, Execution as Jt, RequestConfig as K, CodeContext as Kt, ScrollDirection as L, SessionOptions as Lt, ScreenSizeResponse as M, ProcessStatus as Mt, ScreenshotBytesResponse as N, RemoteMountBucketOptions as Nt, DesktopStartResponse as O, ProcessListResult as Ot, ScreenshotOptions as P, RestoreBackupResult as Pt, ExposePortRequest as Q, TypeOptions as R, StreamOptions as Rt, WriteFileRequest as S, PortExposeResult as St, Desktop as T, ProcessCleanupResult as Tt, ContainerStub as U, isProcess as Ut, BackupClient as V, WatchOptions as Vt, ErrorResponse as W, isProcessStatus as Wt, TunnelInfo as X, RunCodeOptions as Xt, SandboxInterpreterAPI as Y, ExecutionResult as Yt, ExecuteRequest as Z, GitClient as _, ListFilesOptions as _t, CreateSessionRequest as a, CheckChangesResult as at, MkdirRequest as b, MountBucketOptions as bt, DeleteSessionResponse as c, ExecOptions as ct, ProcessClient as d, FileChunk as dt, BackupOptions as et, PortClient as f, FileMetadata as ft, GitCheckoutRequest as g, ISandbox as gt, InterpreterClient as h, GitCheckoutResult as ht, CommandsResponse as i, CheckChangesOptions as it, KeyInput as j, ProcessStartResult as jt, DesktopStatusResponse as k, ProcessLogsResult as kt, PingResponse as l, ExecResult as lt, ExecutionCallbacks as m, FileWatchSSEEvent as mt, getSandbox as n, BucketCredentials as nt, CreateSessionResponse as o, DirectoryBackup as ot, UnexposePortRequest as p, FileStreamEvent as pt, ResponseHandler as q, CreateContextOptions as qt, SandboxClient as r, BucketProvider as rt, DeleteSessionRequest as s, ExecEvent as st, Sandbox as t, BaseExecOptions as tt, UtilityClient as u, ExecutionSession as ut, FileClient as v, LocalMountBucketOptions as vt, CursorPositionResponse as w, Process as wt, ReadFileRequest as x, PortCloseResult as xt, FileOperationRequest as y, LogEvent as yt, CommandClient as z, WaitForLogResult as zt };
3689
+ //# sourceMappingURL=sandbox-KdzTTnWq.d.ts.map