@vite-hub/sandbox 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +118 -53
  2. package/dist/abortable-CR01hzfi.js +57 -0
  3. package/dist/cloudflare-Cog_r2Me.js +910 -0
  4. package/dist/cloudflare-env-lookup-DzI6Xv1Y.js +16 -0
  5. package/dist/cloudflare-failure-CFQhalfh.js +50 -0
  6. package/dist/container-CqfD8yuE.js +868 -0
  7. package/dist/{crabbox-BFCdf41h.js → crabbox-sbV3Zjuo.js} +10 -6
  8. package/dist/error-diagnostics-5QT_BjbQ.js +354 -0
  9. package/dist/error-diagnostics-BJtLRL9w.js +536 -0
  10. package/dist/{file-listing-DECFTdSl.js → file-listing-CHtRrfo1.js} +1 -1
  11. package/dist/{file-lock-CxyVl4Cv.js → file-lock-D0-XPogS.js} +3 -2
  12. package/dist/{index-CXej1Bt0.d.ts → index-DsoQAUb7.d.ts} +94 -19
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +15 -10
  15. package/dist/internal/cloudflare.d.ts +173 -1
  16. package/dist/internal/cloudflare.js +4 -12
  17. package/dist/internal/host-toolchain.d.ts +1 -1
  18. package/dist/internal/host-toolchain.js +6 -7
  19. package/dist/internal/vercel.d.ts +1 -1
  20. package/dist/internal/vercel.js +3 -11
  21. package/dist/invariant-DolT9EEx.js +22 -0
  22. package/dist/module-types-B0LQ5H2S.js +7 -0
  23. package/dist/module-types-DCeJbS9Z.d.ts +110 -0
  24. package/dist/process-sweep-CMaujWE5.js +33 -0
  25. package/dist/provider-resolution-C6AQzuFG.js +133 -0
  26. package/dist/{remote-1Jz2oUMK.js → remote-70ZVZZlq.js} +32 -14
  27. package/dist/runtime-type-Deo4qzxN.js +9 -0
  28. package/dist/{session-DD0S1PDC.js → session-e0lyzjJ3.js} +2 -1
  29. package/dist/size-7AkVwGZb.js +118 -0
  30. package/dist/ssh.d.ts +8 -0
  31. package/dist/ssh.js +107 -40
  32. package/dist/task/index.d.ts +19 -17
  33. package/dist/task/index.js +92 -201
  34. package/dist/task/runtime/provider-loader.d.ts +7 -9
  35. package/dist/task/runtime/provider-loader.js +2 -5
  36. package/dist/task/runtime/providers/cloudflare.d.ts +5 -19
  37. package/dist/task/runtime/providers/cloudflare.js +7 -6
  38. package/dist/task/runtime/providers/vercel.d.ts +3 -3
  39. package/dist/task/runtime/providers/vercel.js +35 -4
  40. package/dist/task/runtime/state.d.ts +4 -1
  41. package/dist/task/runtime/state.js +11 -2
  42. package/dist/task/vite.d.ts +143 -17
  43. package/dist/task/vite.js +723 -400
  44. package/dist/{toolchain-BUVXtQ2m.js → toolchain-BIVGMRty.js} +12 -11
  45. package/dist/{trusted-host-DNMJ-Oig.js → trusted-host-kxkpaQcs.js} +21 -179
  46. package/dist/{vercel-Jtxa9TJx.js → vercel-BGGrNpza.js} +107 -34
  47. package/package.json +15 -12
  48. package/dist/cloudflare-DO0h3Ncf.js +0 -281
  49. package/dist/cloudflare-env-BBJaBbuQ.js +0 -39
  50. package/dist/error-diagnostics-BSysPv-D.js +0 -166
  51. package/dist/error-diagnostics-dGQqfgLt.js +0 -99
  52. package/dist/module-types-BfyRBaiP.js +0 -7
  53. package/dist/module-types-Cis4hrF1.d.ts +0 -95
  54. package/dist/runtime-type-DrmrW5m5.js +0 -42
@@ -1,4 +1,16 @@
1
1
  import { ExecutionAuthority } from "@vite-hub/runtime";
2
+ //#region src/internal/network-policy.d.ts
3
+ /**
4
+ * The outbound network of a Sandbox. The `vercel` and `cloudflare` runtimes take this form.
5
+ * - `"allow-all"`: no limit. This is the default.
6
+ * - `"deny-all"`: no network exit.
7
+ * - `{ allow }`: HTTP and HTTPS only to these hostnames. `"*.example.com"` matches subdomains only.
8
+ * Other protocols have no exit.
9
+ */
10
+ type SandboxNetworkPolicy = "allow-all" | "deny-all" | {
11
+ allow: readonly string[];
12
+ };
13
+ //#endregion
2
14
  //#region src/cloudflare.d.ts
3
15
  interface CloudflareSandboxOptions {
4
16
  cloudflare?: {
@@ -9,6 +21,11 @@ interface CloudflareSandboxOptions {
9
21
  getSandbox?: (namespace: CloudflareDurableObjectNamespace, id: string, options?: CloudflareSandboxOptions["cloudflare"]) => CloudflareSandboxStub;
10
22
  hostname?: string;
11
23
  namespace: CloudflareDurableObjectNamespace;
24
+ /**
25
+ * Outbound network of the Container. Default `"allow-all"`. The policy applies when the Container starts.
26
+ * A Sandbox that runs with another policy restarts. Not available with a custom `getSandbox`.
27
+ */
28
+ networkPolicy?: SandboxNetworkPolicy;
12
29
  sandboxId?: string;
13
30
  }
14
31
  interface CloudflareDurableObjectNamespace {
@@ -16,6 +33,8 @@ interface CloudflareDurableObjectNamespace {
16
33
  idFromName(name: string): unknown;
17
34
  }
18
35
  interface CloudflareSandboxStub {
36
+ /** Stops the `exec` command started with this `id`, without stopping the Sandbox. */
37
+ cancelExec(id: string): Promise<void>;
19
38
  deleteFile?(path: string): Promise<{
20
39
  success: boolean;
21
40
  } | void>;
@@ -23,6 +42,7 @@ interface CloudflareSandboxStub {
23
42
  exec(command: string, options?: {
24
43
  cwd?: string;
25
44
  env?: Record<string, string | undefined>;
45
+ id?: string;
26
46
  timeout?: number;
27
47
  }): Promise<{
28
48
  exitCode: number;
@@ -66,6 +86,7 @@ interface CloudflareSandboxStub {
66
86
  startProcess?(command: string, options?: {
67
87
  cwd?: string;
68
88
  env?: Record<string, string>;
89
+ stdin?: boolean;
69
90
  }): Promise<{
70
91
  getLogs(): Promise<{
71
92
  stderr: string;
@@ -73,10 +94,14 @@ interface CloudflareSandboxStub {
73
94
  }>;
74
95
  id: string;
75
96
  kill(signal?: string): Promise<void>;
97
+ /** Process input, when the stub was asked for it with `stdin: true`. */
98
+ stdin?: WritableStream<Uint8Array>;
76
99
  waitForExit(): Promise<{
77
100
  exitCode: number;
78
101
  }>;
79
102
  }>;
103
+ /** Server-sent events with the process's buffered output, then live output until it exits. */
104
+ streamProcessLogs?(processId: string): Promise<ReadableStream<Uint8Array>>;
80
105
  writeFile(path: string, contents: string, options?: {
81
106
  encoding?: string;
82
107
  }): Promise<{
@@ -84,6 +109,47 @@ interface CloudflareSandboxStub {
84
109
  } | void>;
85
110
  }
86
111
  //#endregion
112
+ //#region src/internal/container.d.ts
113
+ /** A credential that stays on the ViteHub host. The Sandbox sees only a placeholder. */
114
+ interface ContainerSandboxCredential {
115
+ /** Hosts that receive the real value, such as `api.github.com` or `*.example.com:8443`. */
116
+ hosts: readonly string[];
117
+ /** The real value. Resolved on the ViteHub host each time a session opens. */
118
+ value: string | (() => string | Promise<string>);
119
+ }
120
+ /**
121
+ * Egress for a container Sandbox.
122
+ * - `"none"`: no network exit. This is the default.
123
+ * - `{ allow }`: only the listed hosts and the credential hosts, through the broker.
124
+ * - `"open"`: every host, through the broker.
125
+ */
126
+ type ContainerSandboxEgress = "none" | "open" | {
127
+ allow: readonly string[];
128
+ };
129
+ /** Requires rootful Docker Engine 28 or newer on native Linux, through a local or remote Docker context. */
130
+ interface ContainerSandboxOptions {
131
+ /** Image for the Sandbox container. It must have `sh`, coreutils, and GNU `find`, and `git` for a checkout. */
132
+ image: string;
133
+ /** Image for the broker. Defaults to a pinned `mitmproxy/mitmproxy` release. */
134
+ brokerImage?: string;
135
+ /** CPU limit, as for `docker run --cpus`. */
136
+ cpus?: number;
137
+ /**
138
+ * Credentials keyed by the environment variable name in the Sandbox.
139
+ * The broker replaces the placeholder with the real value in HTTPS request headers to the listed hosts only.
140
+ */
141
+ credentials?: Readonly<Record<string, ContainerSandboxCredential>>;
142
+ /** Docker CLI command. Defaults to `docker`. The CLI uses the host Docker context. */
143
+ docker?: string;
144
+ egress?: ContainerSandboxEgress;
145
+ /** Memory limit in bytes, as for `docker run --memory`. */
146
+ memoryBytes?: number;
147
+ /** Process limit, as for `docker run --pids-limit`. Defaults to 4096. */
148
+ pidsLimit?: number;
149
+ /** Container user, as for `docker run --user`. Defaults to the image user. */
150
+ user?: string;
151
+ }
152
+ //#endregion
87
153
  //#region src/internal/crabbox.d.ts
88
154
  interface CrabboxOptions {
89
155
  /** Enables loopback port URLs when the target shares the ViteHub process network namespace. */
@@ -95,21 +161,8 @@ interface CrabboxOptions {
95
161
  stateRoot?: string;
96
162
  }
97
163
  //#endregion
98
- //#region src/internal/session-memory.d.ts
99
- interface TrustedHostResources {
100
- /** Writable delegated cgroup v2 parent. The controller must live in a separate subgroup. */
101
- cgroupParent: string;
102
- /** Aggregate resident memory limit for this session's commands and descendants. */
103
- memoryMaxBytes: number;
104
- memoryHighBytes?: number;
105
- /** Aggregate swap limit. Defaults to zero. */
106
- memorySwapMaxBytes?: number;
107
- }
108
- //#endregion
109
164
  //#region src/internal/trusted-host.d.ts
110
165
  interface TrustedHostOptions {
111
- /** Linux-only aggregate limits for session commands. Requires cgroup v2 delegation. */
112
- resources?: TrustedHostResources;
113
166
  stateRoot?: string;
114
167
  }
115
168
  //#endregion
@@ -160,20 +213,32 @@ interface VercelSandboxCreateOptions {
160
213
  resources?: {
161
214
  vcpus?: number;
162
215
  };
163
- runtime: string;
216
+ /** Vercel takes the runtime from the snapshot for a snapshot source, so ViteHub omits it then. */
217
+ runtime?: string;
164
218
  signal?: AbortSignal;
165
219
  source?: VercelSandboxSource;
166
220
  teamId?: string;
167
221
  timeout?: number;
168
222
  token?: string;
169
223
  }
224
+ /** The signals that the Vercel Sandbox SDK sends by name. Other signals use their number. */
225
+ declare const vercelSignalNames: readonly ["SIGHUP", "SIGINT", "SIGQUIT", "SIGKILL", "SIGTERM", "SIGCONT", "SIGSTOP"];
226
+ type VercelSandboxSignal = typeof vercelSignalNames[number] | number;
170
227
  interface VercelSandboxCommand {
171
- kill(): Promise<void>;
228
+ closeStdin(): Promise<void>;
229
+ kill(signal?: VercelSandboxSignal): Promise<void>;
230
+ logs(options?: {
231
+ signal?: AbortSignal;
232
+ }): AsyncIterable<{
233
+ data: string;
234
+ stream: "stderr" | "stdout";
235
+ }>;
172
236
  stderr(): Promise<string>;
173
237
  stdout(): Promise<string>;
174
238
  wait(): Promise<{
175
239
  exitCode: number;
176
240
  }>;
241
+ writeStdin(data: Uint8Array): Promise<void>;
177
242
  }
178
243
  interface VercelSandboxInstance {
179
244
  domain(port: number): string;
@@ -227,6 +292,7 @@ interface VercelSandboxInstance {
227
292
  detached?: boolean;
228
293
  env?: Record<string, string>;
229
294
  signal?: AbortSignal;
295
+ stdin?: boolean;
230
296
  }): Promise<VercelSandboxCommand>;
231
297
  stop?(options?: {
232
298
  blocking?: boolean;
@@ -346,6 +412,8 @@ type BuiltInSandboxRuntime = BuiltInSandboxRuntimeName | ({
346
412
  } & TrustedHostOptions) | ({
347
413
  kind: "cloudflare";
348
414
  } & CloudflareSandboxOptions) | ({
415
+ kind: "container";
416
+ } & ContainerSandboxOptions) | ({
349
417
  kind: "vercel";
350
418
  } & VercelSandboxOptions);
351
419
  type SandboxRuntimeDefinition = BuiltInSandboxRuntime | SandboxRuntime;
@@ -372,6 +440,15 @@ interface SandboxExecOptions {
372
440
  signal?: AbortSignal;
373
441
  timeout?: number;
374
442
  }
443
+ interface SandboxSpawnOptions extends SandboxExecOptions {
444
+ /**
445
+ * Keep process input open and expose it as `SandboxProcess.stdin`.
446
+ * The `vercel` and `cloudflare` runtimes forward input only when this is set, because a command that reads stdin then waits for the caller to close it.
447
+ * The `container` runtime also forwards input only when this is set.
448
+ * `trusted-host` and `crabbox` always forward input.
449
+ */
450
+ stdin?: boolean;
451
+ }
375
452
  interface SandboxExecResult {
376
453
  readonly code: number;
377
454
  readonly ok: boolean;
@@ -431,7 +508,7 @@ interface SandboxSession {
431
508
  readonly ports?: SandboxPorts;
432
509
  /** Provisioned toolchain, when the Sandbox declares one. */
433
510
  readonly toolchain?: SandboxResolvedToolchain;
434
- readonly spawn?: (command: string, args?: readonly string[], options?: SandboxExecOptions) => Promise<SandboxProcess>;
511
+ readonly spawn?: (command: string, args?: readonly string[], options?: SandboxSpawnOptions) => Promise<SandboxProcess>;
435
512
  close(): Promise<void>;
436
513
  exec(command: string, args?: readonly string[], options?: SandboxExecOptions): Promise<SandboxExecResult>;
437
514
  /** Replace the session workspace with a host checkout's working tree, when the runtime has a faster transfer. */
@@ -481,8 +558,6 @@ interface SandboxResolvedRequirement {
481
558
  readonly timeout?: number;
482
559
  }
483
560
  interface SandboxPlan {
484
- /** Configured trusted-host command limits. Absent on runtimes without this contract. */
485
- readonly resources?: TrustedHostOptions["resources"];
486
561
  readonly cache: {
487
562
  readonly state: "disposable";
488
563
  };
@@ -516,4 +591,4 @@ interface ResolveSandboxOptions {
516
591
  }
517
592
  declare function resolveSandbox<Context>(definition: SandboxDefinition<Context>, context: Context, options?: ResolveSandboxOptions): Promise<Sandbox>;
518
593
  //#endregion
519
- export { CrabboxOptions as $, SandboxRuntime as A, SandboxToolchainPin as B, SandboxPorts as C, SandboxRequirement as D, SandboxRemoveFileOptions as E, SandboxSession as F, VercelFileStat as G, SandboxToolchainPlan as H, SandboxToolchain as I, VercelSandboxInstance as J, VercelSandboxCommand as K, SandboxToolchainInput as L, SandboxRuntimeInput as M, SandboxRuntimeOpenOptions as N, SandboxResolvedRequirement as O, SandboxRuntimePlan as P, TrustedHostOptions as Q, SandboxToolchainOptions as R, SandboxPlan as S, SandboxProcessExit as T, SandboxValue as U, SandboxToolchainPins as V, resolveSandbox as W, VercelSandboxOptions as X, VercelSandboxNetworkPolicy as Y, VercelSandboxSource as Z, SandboxFileOptions as _, ResolvedSandboxFile as a, SandboxListFilesOptions as b, ResolvedSandboxState as c, SandboxDefinition as d, CloudflareDurableObjectNamespace as et, SandboxEnvironment as f, SandboxFileEntry as g, SandboxFile as h, ResolvedSandboxCheckout as i, SandboxRuntimeDefinition as j, SandboxResolvedToolchain as k, Sandbox as l, SandboxExecResult as m, BuiltInSandboxRuntimeName as n, CloudflareSandboxStub as nt, ResolvedSandboxPlan as o, SandboxExecOptions as p, VercelSandboxCreateOptions as q, ResolveSandboxOptions as r, ResolvedSandboxRequirementInput as s, BuiltInSandboxRuntime as t, CloudflareSandboxOptions as tt, SandboxCheckout as u, SandboxFiles as v, SandboxProcess as w, SandboxOpenOptions as x, SandboxHome as y, SandboxToolchainPackageManagerPin as z };
594
+ export { TrustedHostOptions as $, SandboxRuntime as A, SandboxToolchainPackageManagerPin as B, SandboxPorts as C, SandboxRequirement as D, SandboxRemoveFileOptions as E, SandboxSession as F, resolveSandbox as G, SandboxToolchainPins as H, SandboxSpawnOptions as I, VercelSandboxCreateOptions as J, VercelFileStat as K, SandboxToolchain as L, SandboxRuntimeInput as M, SandboxRuntimeOpenOptions as N, SandboxResolvedRequirement as O, SandboxRuntimePlan as P, VercelSandboxSource as Q, SandboxToolchainInput as R, SandboxPlan as S, SandboxProcessExit as T, SandboxToolchainPlan as U, SandboxToolchainPin as V, SandboxValue as W, VercelSandboxNetworkPolicy as X, VercelSandboxInstance as Y, VercelSandboxOptions as Z, SandboxFileOptions as _, ResolvedSandboxFile as a, CloudflareSandboxOptions as at, SandboxListFilesOptions as b, ResolvedSandboxState as c, SandboxDefinition as d, CrabboxOptions as et, SandboxEnvironment as f, SandboxFileEntry as g, SandboxFile as h, ResolvedSandboxCheckout as i, CloudflareDurableObjectNamespace as it, SandboxRuntimeDefinition as j, SandboxResolvedToolchain as k, Sandbox as l, SandboxExecResult as m, BuiltInSandboxRuntimeName as n, ContainerSandboxEgress as nt, ResolvedSandboxPlan as o, CloudflareSandboxStub as ot, SandboxExecOptions as p, VercelSandboxCommand as q, ResolveSandboxOptions as r, ContainerSandboxOptions as rt, ResolvedSandboxRequirementInput as s, SandboxNetworkPolicy as st, BuiltInSandboxRuntime as t, ContainerSandboxCredential as tt, SandboxCheckout as u, SandboxFiles as v, SandboxProcess as w, SandboxOpenOptions as x, SandboxHome as y, SandboxToolchainOptions as z };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as CrabboxOptions, A as SandboxRuntime, B as SandboxToolchainPin, C as SandboxPorts, D as SandboxRequirement, E as SandboxRemoveFileOptions, F as SandboxSession, G as VercelFileStat, H as SandboxToolchainPlan, I as SandboxToolchain, J as VercelSandboxInstance, K as VercelSandboxCommand, L as SandboxToolchainInput, M as SandboxRuntimeInput, N as SandboxRuntimeOpenOptions, O as SandboxResolvedRequirement, P as SandboxRuntimePlan, Q as TrustedHostOptions, R as SandboxToolchainOptions, S as SandboxPlan, T as SandboxProcessExit, U as SandboxValue, V as SandboxToolchainPins, W as resolveSandbox, X as VercelSandboxOptions, Y as VercelSandboxNetworkPolicy, Z as VercelSandboxSource, _ as SandboxFileOptions, a as ResolvedSandboxFile, b as SandboxListFilesOptions, c as ResolvedSandboxState, d as SandboxDefinition, et as CloudflareDurableObjectNamespace, f as SandboxEnvironment, g as SandboxFileEntry, h as SandboxFile, i as ResolvedSandboxCheckout, j as SandboxRuntimeDefinition, k as SandboxResolvedToolchain, l as Sandbox, m as SandboxExecResult, n as BuiltInSandboxRuntimeName, nt as CloudflareSandboxStub, o as ResolvedSandboxPlan, p as SandboxExecOptions, q as VercelSandboxCreateOptions, r as ResolveSandboxOptions, s as ResolvedSandboxRequirementInput, t as BuiltInSandboxRuntime, tt as CloudflareSandboxOptions, u as SandboxCheckout, v as SandboxFiles, w as SandboxProcess, x as SandboxOpenOptions, y as SandboxHome, z as SandboxToolchainPackageManagerPin } from "./index-CXej1Bt0.js";
2
- export { BuiltInSandboxRuntime, BuiltInSandboxRuntimeName, type CloudflareDurableObjectNamespace, type CloudflareSandboxOptions, type CloudflareSandboxStub, type CrabboxOptions, ResolveSandboxOptions, ResolvedSandboxCheckout, ResolvedSandboxFile, ResolvedSandboxPlan, ResolvedSandboxRequirementInput, ResolvedSandboxState, Sandbox, SandboxCheckout, SandboxDefinition, SandboxEnvironment, SandboxExecOptions, SandboxExecResult, SandboxFile, SandboxFileEntry, SandboxFileOptions, SandboxFiles, SandboxHome, SandboxListFilesOptions, SandboxOpenOptions, SandboxPlan, SandboxPorts, SandboxProcess, SandboxProcessExit, SandboxRemoveFileOptions, SandboxRequirement, SandboxResolvedRequirement, SandboxResolvedToolchain, SandboxRuntime, SandboxRuntimeDefinition, SandboxRuntimeInput, SandboxRuntimeOpenOptions, SandboxRuntimePlan, SandboxSession, SandboxToolchain, SandboxToolchainInput, SandboxToolchainOptions, SandboxToolchainPackageManagerPin, SandboxToolchainPin, SandboxToolchainPins, SandboxToolchainPlan, SandboxValue, type TrustedHostOptions, type VercelFileStat, type VercelSandboxCommand, type VercelSandboxCreateOptions, type VercelSandboxInstance, type VercelSandboxNetworkPolicy, type VercelSandboxOptions, type VercelSandboxSource, resolveSandbox };
1
+ import { $ as TrustedHostOptions, A as SandboxRuntime, B as SandboxToolchainPackageManagerPin, C as SandboxPorts, D as SandboxRequirement, E as SandboxRemoveFileOptions, F as SandboxSession, G as resolveSandbox, H as SandboxToolchainPins, I as SandboxSpawnOptions, J as VercelSandboxCreateOptions, K as VercelFileStat, L as SandboxToolchain, M as SandboxRuntimeInput, N as SandboxRuntimeOpenOptions, O as SandboxResolvedRequirement, P as SandboxRuntimePlan, Q as VercelSandboxSource, R as SandboxToolchainInput, S as SandboxPlan, T as SandboxProcessExit, U as SandboxToolchainPlan, V as SandboxToolchainPin, W as SandboxValue, X as VercelSandboxNetworkPolicy, Y as VercelSandboxInstance, Z as VercelSandboxOptions, _ as SandboxFileOptions, a as ResolvedSandboxFile, at as CloudflareSandboxOptions, b as SandboxListFilesOptions, c as ResolvedSandboxState, d as SandboxDefinition, et as CrabboxOptions, f as SandboxEnvironment, g as SandboxFileEntry, h as SandboxFile, i as ResolvedSandboxCheckout, it as CloudflareDurableObjectNamespace, j as SandboxRuntimeDefinition, k as SandboxResolvedToolchain, l as Sandbox, m as SandboxExecResult, n as BuiltInSandboxRuntimeName, nt as ContainerSandboxEgress, o as ResolvedSandboxPlan, ot as CloudflareSandboxStub, p as SandboxExecOptions, q as VercelSandboxCommand, r as ResolveSandboxOptions, rt as ContainerSandboxOptions, s as ResolvedSandboxRequirementInput, st as SandboxNetworkPolicy, t as BuiltInSandboxRuntime, tt as ContainerSandboxCredential, u as SandboxCheckout, v as SandboxFiles, w as SandboxProcess, x as SandboxOpenOptions, y as SandboxHome, z as SandboxToolchainOptions } from "./index-DsoQAUb7.js";
2
+ export { BuiltInSandboxRuntime, BuiltInSandboxRuntimeName, type CloudflareDurableObjectNamespace, type CloudflareSandboxOptions, type CloudflareSandboxStub, type ContainerSandboxCredential, type ContainerSandboxEgress, type ContainerSandboxOptions, type CrabboxOptions, ResolveSandboxOptions, ResolvedSandboxCheckout, ResolvedSandboxFile, ResolvedSandboxPlan, ResolvedSandboxRequirementInput, ResolvedSandboxState, Sandbox, SandboxCheckout, SandboxDefinition, SandboxEnvironment, SandboxExecOptions, SandboxExecResult, SandboxFile, SandboxFileEntry, SandboxFileOptions, SandboxFiles, SandboxHome, SandboxListFilesOptions, type SandboxNetworkPolicy, SandboxOpenOptions, SandboxPlan, SandboxPorts, SandboxProcess, SandboxProcessExit, SandboxRemoveFileOptions, SandboxRequirement, SandboxResolvedRequirement, SandboxResolvedToolchain, SandboxRuntime, SandboxRuntimeDefinition, SandboxRuntimeInput, SandboxRuntimeOpenOptions, SandboxRuntimePlan, SandboxSession, SandboxSpawnOptions, SandboxToolchain, SandboxToolchainInput, SandboxToolchainOptions, SandboxToolchainPackageManagerPin, SandboxToolchainPin, SandboxToolchainPins, SandboxToolchainPlan, SandboxValue, type TrustedHostOptions, type VercelFileStat, type VercelSandboxCommand, type VercelSandboxCreateOptions, type VercelSandboxInstance, type VercelSandboxNetworkPolicy, type VercelSandboxOptions, type VercelSandboxSource, resolveSandbox };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as isBuiltInSandboxRuntime, t as hasDeclaredSandboxRuntimeMember } from "./runtime-DHp6ImeP.js";
2
- import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BSysPv-D.js";
2
+ import { t as sandboxErrorDiagnostics } from "./error-diagnostics-BJtLRL9w.js";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { readFile, realpath } from "node:fs/promises";
5
5
  import { isAbsolute, posix, relative, resolve } from "node:path";
@@ -7,6 +7,7 @@ import { normalizeExecutionAuthority } from "@vite-hub/runtime";
7
7
  //#region src/index.ts
8
8
  const reservedRuntimeNames = /* @__PURE__ */ new Set([
9
9
  "cloudflare",
10
+ "container",
10
11
  "crabbox",
11
12
  "trusted-host",
12
13
  "vercel"
@@ -18,15 +19,15 @@ async function resolveSandboxRuntime(value) {
18
19
  }
19
20
  if (typeof value === "string") {
20
21
  if (value === "crabbox") {
21
- const { createCrabboxRuntime } = await import("./crabbox-BFCdf41h.js");
22
+ const { createCrabboxRuntime } = await import("./crabbox-sbV3Zjuo.js");
22
23
  return createCrabboxRuntime();
23
24
  }
24
25
  if (value === "trusted-host") {
25
- const { createTrustedHostRuntime } = await import("./trusted-host-DNMJ-Oig.js");
26
+ const { createTrustedHostRuntime } = await import("./trusted-host-kxkpaQcs.js");
26
27
  return createTrustedHostRuntime();
27
28
  }
28
29
  if (value === "vercel") {
29
- const { createVercelRuntime } = await import("./vercel-Jtxa9TJx.js").then((n) => n.n);
30
+ const { createVercelRuntime } = await import("./vercel-BGGrNpza.js").then((n) => n.r);
30
31
  return createVercelRuntime();
31
32
  }
32
33
  throw sandboxErrorDiagnostics.SANDBOX_R0031({ message: `[vitehub] Unknown Sandbox runtime "${value}". Expected "crabbox", "trusted-host", "vercel", a tagged built-in configuration, or a custom runtime.` });
@@ -34,22 +35,26 @@ async function resolveSandboxRuntime(value) {
34
35
  if (!value || typeof value !== "object" || Array.isArray(value)) throw sandboxErrorDiagnostics.SANDBOX_R0032({ message: "[vitehub] Sandbox requires an explicit built-in runtime value or custom runtime object." });
35
36
  const { kind, ...options } = value;
36
37
  if (kind === "crabbox") {
37
- const { createCrabboxRuntime } = await import("./crabbox-BFCdf41h.js");
38
+ const { createCrabboxRuntime } = await import("./crabbox-sbV3Zjuo.js");
38
39
  return createCrabboxRuntime(options);
39
40
  }
40
41
  if (kind === "trusted-host") {
41
- const { createTrustedHostRuntime } = await import("./trusted-host-DNMJ-Oig.js");
42
+ const { createTrustedHostRuntime } = await import("./trusted-host-kxkpaQcs.js");
42
43
  return createTrustedHostRuntime(options);
43
44
  }
44
45
  if (kind === "cloudflare") {
45
- const { createCloudflareRuntime } = await import("./cloudflare-DO0h3Ncf.js").then((n) => n.t);
46
+ const { createCloudflareRuntime } = await import("./cloudflare-Cog_r2Me.js").then((n) => n.t);
46
47
  return createCloudflareRuntime(options);
47
48
  }
48
49
  if (kind === "vercel") {
49
- const { createVercelRuntime } = await import("./vercel-Jtxa9TJx.js").then((n) => n.n);
50
+ const { createVercelRuntime } = await import("./vercel-BGGrNpza.js").then((n) => n.r);
50
51
  return createVercelRuntime(options);
51
52
  }
52
- throw sandboxErrorDiagnostics.SANDBOX_R0033({ message: `[vitehub] Unknown Sandbox runtime kind "${String(kind)}". Expected "crabbox", "trusted-host", "cloudflare", or "vercel".` });
53
+ if (kind === "container") {
54
+ const { createContainerRuntime } = await import("./container-CqfD8yuE.js");
55
+ return createContainerRuntime(options);
56
+ }
57
+ throw sandboxErrorDiagnostics.SANDBOX_R0033({ message: `[vitehub] Unknown Sandbox runtime kind "${String(kind)}". Expected "crabbox", "trusted-host", "cloudflare", "container", or "vercel".` });
53
58
  }
54
59
  function isSandboxRuntime(value) {
55
60
  if (!value || typeof value !== "object") return false;
@@ -137,7 +142,7 @@ async function resolveSandbox(definition, context, options = {}) {
137
142
  /** Read toolchain pins now unless they come from a checkout that exists only after open. */
138
143
  async function resolveToolchain(declaration, projectRoot) {
139
144
  if (declaration === void 0) return;
140
- const [{ normalizeToolchain, readToolchainPins, toolchainReadsProject }, { readHostProjectFiles }] = await Promise.all([import("./toolchain-BUVXtQ2m.js").then((n) => n.i), import("./internal/host-toolchain.js")]);
145
+ const [{ normalizeToolchain, readToolchainPins, toolchainReadsProject }, { readHostProjectFiles }] = await Promise.all([import("./toolchain-BIVGMRty.js").then((n) => n.i), import("./internal/host-toolchain.js")]);
141
146
  const toolchain = normalizeToolchain(declaration, "sandbox.toolchain");
142
147
  if (!toolchain) return;
143
148
  if (!projectRoot && toolchainReadsProject(toolchain)) return toolchain;
@@ -1,4 +1,176 @@
1
- import { l as Sandbox, tt as CloudflareSandboxOptions } from "../index-CXej1Bt0.js";
1
+ import { at as CloudflareSandboxOptions, l as Sandbox } from "../index-DsoQAUb7.js";
2
+ //#region src/internal/cloudflare-durable-object.d.ts
3
+ interface CloudflareContainerExecProcess {
4
+ readonly exitCode: Promise<number>;
5
+ readonly stderr: ReadableStream<Uint8Array> | null;
6
+ readonly stdin: WritableStream<Uint8Array> | null;
7
+ readonly stdout: ReadableStream<Uint8Array> | null;
8
+ kill(signal?: number): void;
9
+ output(): Promise<{
10
+ exitCode: number;
11
+ stderr: ArrayBuffer;
12
+ stdout: ArrayBuffer;
13
+ }>;
14
+ }
15
+ /** The part of the Workers `Container` API this Durable Object uses. */
16
+ interface CloudflareContainer {
17
+ readonly running: boolean;
18
+ destroy(error?: unknown): Promise<void>;
19
+ exec(command: string[], options?: {
20
+ cwd?: string;
21
+ env?: Record<string, string>;
22
+ signal?: AbortSignal;
23
+ stderr?: "pipe" | "ignore" | "combined";
24
+ stdin?: ReadableStream | "pipe";
25
+ stdout?: "pipe" | "ignore";
26
+ }): Promise<CloudflareContainerExecProcess>;
27
+ /** Sends HTTP requests on port 80 to `target` through `handler`. Missing on Workers runtimes without outbound interception. */
28
+ interceptOutboundHttp?(target: string, handler: unknown): Promise<void>;
29
+ /** Decrypts HTTPS requests on port 443 to `target` and sends them through `handler`. */
30
+ interceptOutboundHttps?(target: string, handler: unknown): Promise<void>;
31
+ setInactivityTimeout(durationMs: number | bigint): Promise<void>;
32
+ start(options?: {
33
+ enableInternet?: boolean;
34
+ labels?: Record<string, string>;
35
+ }): void;
36
+ }
37
+ interface CloudflareDurableObjectState {
38
+ readonly container?: CloudflareContainer;
39
+ /** The Worker's exported entrypoints. Needs compatibility date 2025-11-17 or later, or the `enable_ctx_exports` flag. */
40
+ readonly exports?: Readonly<Record<string, unknown>>;
41
+ readonly id: {
42
+ toString(): string;
43
+ readonly name?: string;
44
+ };
45
+ readonly storage: {
46
+ get<T>(key: string): Promise<T | undefined>;
47
+ put(key: string, value: unknown): Promise<void>;
48
+ };
49
+ }
50
+ /** The part of `@cloudflare/sandbox` `Files` this Durable Object uses. */
51
+ interface CloudflareSandboxFiles {
52
+ mkdir(path: string, options?: {
53
+ cwd?: string;
54
+ recursive?: boolean;
55
+ }): Promise<void>;
56
+ readFile(path: string, options?: {
57
+ cwd?: string;
58
+ }): Promise<Response>;
59
+ remove(path: string, options?: {
60
+ cwd?: string;
61
+ force?: boolean;
62
+ recursive?: boolean;
63
+ }): Promise<void>;
64
+ rename(source: string, destination: string, options?: {
65
+ cwd?: string;
66
+ }): Promise<void>;
67
+ stat(path: string, options?: {
68
+ cwd?: string;
69
+ }): Promise<unknown>;
70
+ writeFile(path: string, content: Uint8Array, options?: {
71
+ cwd?: string;
72
+ }): Promise<void>;
73
+ }
74
+ interface CloudflareSandboxDurableObjectDependencies {
75
+ DurableObject: abstract new (ctx: any, env: any) => object;
76
+ Files: new (container: Pick<CloudflareContainer, "exec">) => CloudflareSandboxFiles;
77
+ /** The name of the exported `WorkerEntrypoint` that sends allowed outbound requests on unchanged. */
78
+ outboundEntrypoint?: string;
79
+ SandboxFileError: {
80
+ is(cause: unknown): cause is Error & {
81
+ code: string;
82
+ };
83
+ };
84
+ }
85
+ interface CloudflareSandboxConfiguration {
86
+ keepAlive?: boolean;
87
+ /** Validated by the caller. Missing means `"allow-all"`, as for Containers that started before this option existed. */
88
+ networkPolicy?: "allow-all" | "deny-all" | {
89
+ allow: readonly string[];
90
+ };
91
+ sleepAfter?: number | string;
92
+ }
93
+ /** The RPC methods of the generated Sandbox Durable Object, matching `CloudflareSandboxStub`. */
94
+ interface CloudflareSandboxDurableObject {
95
+ configure(configuration: CloudflareSandboxConfiguration): Promise<void>;
96
+ deleteFile(path: string): Promise<{
97
+ success: boolean;
98
+ }>;
99
+ destroy(): Promise<void>;
100
+ /** Stops the `exec` command started with this `id`. The Container and other commands keep running. */
101
+ cancelExec(id: string): Promise<void>;
102
+ exec(command: string, options?: CloudflareExecOptions): Promise<{
103
+ exitCode: number;
104
+ stderr: string;
105
+ stdout: string;
106
+ success: boolean;
107
+ }>;
108
+ exists(path: string): Promise<{
109
+ exists: boolean;
110
+ }>;
111
+ mkdir(path: string, options?: {
112
+ recursive?: boolean;
113
+ }): Promise<{
114
+ success: boolean;
115
+ }>;
116
+ moveFile(source: string, destination: string): Promise<{
117
+ success: boolean;
118
+ }>;
119
+ readFile(path: string, options?: {
120
+ encoding?: string;
121
+ }): Promise<{
122
+ content: string;
123
+ success: boolean;
124
+ }>;
125
+ startProcess(command: string, options?: {
126
+ cwd?: string;
127
+ env?: Record<string, string>;
128
+ stdin?: boolean;
129
+ }): Promise<{
130
+ getLogs(): Promise<{
131
+ stderr: string;
132
+ stdout: string;
133
+ }>;
134
+ id: string;
135
+ kill(signal?: string): Promise<void>;
136
+ stdin?: WritableStream<Uint8Array>;
137
+ waitForExit(): Promise<{
138
+ exitCode: number;
139
+ }>;
140
+ }>;
141
+ streamProcessLogs(processId: string): Promise<ReadableStream<Uint8Array>>;
142
+ writeFile(path: string, contents: string, options?: {
143
+ encoding?: string;
144
+ }): Promise<{
145
+ success: boolean;
146
+ }>;
147
+ }
148
+ interface CloudflareExecOptions {
149
+ cwd?: string;
150
+ env?: Record<string, string | undefined>;
151
+ /** Names the command for `cancelExec`. */
152
+ id?: string;
153
+ timeout?: number;
154
+ }
155
+ interface CloudflareSandboxOutboundDependencies {
156
+ WorkerEntrypoint: abstract new (ctx: any, env: any) => object;
157
+ }
158
+ /** What the Durable Object passes to each outbound intercept. */
159
+ interface CloudflareSandboxOutboundProps {
160
+ allow: readonly string[];
161
+ }
162
+ /**
163
+ * The Worker entrypoint that receives the intercepted HTTP and HTTPS requests of a Sandbox Container.
164
+ * Cloudflare picks an HTTPS intercept by TLS SNI, but the request URL comes from the Host header that the
165
+ * Container sends. So the entrypoint checks the URL against the allowlist again before it fetches.
166
+ */
167
+ export declare function createCloudflareSandboxOutbound(dependencies: CloudflareSandboxOutboundDependencies): new (ctx: {
168
+ readonly props?: Partial<CloudflareSandboxOutboundProps>;
169
+ }, env: unknown) => {
170
+ fetch(request: Request): Promise<Response>;
171
+ };
172
+ export declare function createCloudflareSandboxDurableObject(dependencies: CloudflareSandboxDurableObjectDependencies): new (ctx: CloudflareDurableObjectState, env: unknown) => CloudflareSandboxDurableObject;
173
+ //#endregion
2
174
  //#region src/internal/cloudflare.d.ts
3
175
  export declare function resolveCloudflareSandbox(options: CloudflareSandboxOptions, requirements: readonly string[]): Promise<Sandbox>;
4
176
  //#endregion
@@ -1,16 +1,8 @@
1
- import { a as resolveRemoteSandboxRuntime } from "../remote-1Jz2oUMK.js";
2
- import { n as createCloudflareRuntime } from "../cloudflare-DO0h3Ncf.js";
1
+ import { a as resolveRemoteSandboxRuntime } from "../remote-70ZVZZlq.js";
2
+ import { i as createCloudflareSandboxOutbound, n as createCloudflareRuntime, r as createCloudflareSandboxDurableObject } from "../cloudflare-Cog_r2Me.js";
3
3
  //#region src/internal/cloudflare.ts
4
4
  async function resolveCloudflareSandbox(options, requirements) {
5
- const getSandbox = options.getSandbox ?? await loadCloudflareSandbox();
6
- return await resolveRemoteSandboxRuntime(createCloudflareRuntime({
7
- ...options,
8
- getSandbox
9
- }), requirements);
10
- }
11
- async function loadCloudflareSandbox() {
12
- const { getSandbox } = await import("@cloudflare/sandbox");
13
- return getSandbox;
5
+ return await resolveRemoteSandboxRuntime(createCloudflareRuntime(options), requirements);
14
6
  }
15
7
  //#endregion
16
- export { resolveCloudflareSandbox };
8
+ export { createCloudflareSandboxDurableObject, createCloudflareSandboxOutbound, resolveCloudflareSandbox };
@@ -1,4 +1,4 @@
1
- import { I as SandboxToolchain, L as SandboxToolchainInput, k as SandboxResolvedToolchain } from "../index-CXej1Bt0.js";
1
+ import { L as SandboxToolchain, R as SandboxToolchainInput, k as SandboxResolvedToolchain } from "../index-DsoQAUb7.js";
2
2
  //#region src/internal/host-toolchain.d.ts
3
3
  export interface HostToolchainOptions {
4
4
  abortSignal?: AbortSignal;
@@ -1,12 +1,11 @@
1
- import { t as sandboxErrorDiagnostics } from "../error-diagnostics-BSysPv-D.js";
2
- import { n as isRuntimeString, t as isRuntimeNumber } from "../runtime-type-DrmrW5m5.js";
3
- import { t as acquireFileLock } from "../file-lock-CxyVl4Cv.js";
4
- import { a as verifyToolchain, n as provisionToolchain, r as toolchainProjectFiles, t as normalizeToolchain } from "../toolchain-BUVXtQ2m.js";
1
+ import { t as sandboxErrorDiagnostics } from "../error-diagnostics-BJtLRL9w.js";
2
+ import { t as acquireFileLock } from "../file-lock-D0-XPogS.js";
3
+ import { a as verifyToolchain, n as provisionToolchain, r as toolchainProjectFiles, t as normalizeToolchain } from "../toolchain-BIVGMRty.js";
5
4
  import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
6
5
  import { delimiter, dirname, join, resolve } from "node:path";
7
6
  import { execFile } from "node:child_process";
8
- import { homedir } from "node:os";
9
7
  import { promisify } from "node:util";
8
+ import { homedir } from "node:os";
10
9
  //#region src/internal/host-toolchain.ts
11
10
  /** Default host cache. A configured Sandbox stateRoot keeps toolchains beside durable state. */
12
11
  function hostToolchainCacheRoot(stateRoot) {
@@ -52,10 +51,10 @@ async function provisionHostToolchain(toolchain, directory, options = {}) {
52
51
  } catch (error) {
53
52
  options.abortSignal?.throwIfAborted();
54
53
  const code = error instanceof Error && "code" in error ? error.code : void 0;
55
- if (!isRuntimeNumber(code)) throw error;
54
+ if (typeof code !== "number") throw error;
56
55
  const output = (name) => {
57
56
  const value = error instanceof Error && name in error ? Reflect.get(error, name) : void 0;
58
- return isRuntimeString(value) ? value : "";
57
+ return typeof value === "string" ? value : "";
59
58
  };
60
59
  return {
61
60
  exitCode: code,
@@ -1,4 +1,4 @@
1
- import { X as VercelSandboxOptions, l as Sandbox } from "../index-CXej1Bt0.js";
1
+ import { Z as VercelSandboxOptions, l as Sandbox } from "../index-DsoQAUb7.js";
2
2
  //#region src/internal/vercel.d.ts
3
3
  export declare function resolveVercelSandbox(options: VercelSandboxOptions, requirements: readonly string[]): Promise<Sandbox>;
4
4
  //#endregion
@@ -1,16 +1,8 @@
1
- import { a as resolveRemoteSandboxRuntime } from "../remote-1Jz2oUMK.js";
2
- import { t as createVercelRuntime } from "../vercel-Jtxa9TJx.js";
1
+ import { a as resolveRemoteSandboxRuntime } from "../remote-70ZVZZlq.js";
2
+ import { t as createVercelRuntime } from "../vercel-BGGrNpza.js";
3
3
  //#region src/internal/vercel.ts
4
4
  async function resolveVercelSandbox(options, requirements) {
5
- const create = options.create ?? await loadVercelSandbox();
6
- return await resolveRemoteSandboxRuntime(createVercelRuntime({
7
- ...options,
8
- create
9
- }), requirements);
10
- }
11
- async function loadVercelSandbox() {
12
- const { Sandbox } = await import("@vercel/sandbox");
13
- return async (createOptions) => await Sandbox.create(createOptions);
5
+ return await resolveRemoteSandboxRuntime(createVercelRuntime(options), requirements);
14
6
  }
15
7
  //#endregion
16
8
  export { resolveVercelSandbox };
@@ -0,0 +1,22 @@
1
+ import { defineDiagnostics } from "nostics";
2
+ //#region ../internal/src/invariant.ts
3
+ const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
+ docsBase: "https://vitehub.dev/docs/development/diagnostics",
5
+ codes: { INTERNAL_INVARIANT_FAILED: {
6
+ why: ({ what }) => `ViteHub reached a state that it does not expect: ${what}`,
7
+ fix: "This is a ViteHub bug. Open an issue at https://github.com/vite-hub/vitehub/issues with this error message and its stack trace."
8
+ } }
9
+ });
10
+ /**
11
+ * The error for a state that only a ViteHub bug can reach, such as an impossible branch. `what` says which rule broke.
12
+ * Use a code from the package catalog when a developer can cause the error or fix it.
13
+ */
14
+ function invariantError(what) {
15
+ return invariantDiagnostics.INTERNAL_INVARIANT_FAILED({ what });
16
+ }
17
+ /** Throws `INTERNAL_INVARIANT_FAILED` when `condition` is falsy. */
18
+ function invariant(condition, what) {
19
+ if (!condition) throw invariantError(what);
20
+ }
21
+ //#endregion
22
+ export { invariantError as n, invariant as t };
@@ -0,0 +1,7 @@
1
+ //#region src/task/module-types.ts
2
+ function getSandboxTaskFeatureDriver(config) {
3
+ if (!config || typeof config !== "object" || typeof config.driver !== "string") return void 0;
4
+ return config;
5
+ }
6
+ //#endregion
7
+ export { getSandboxTaskFeatureDriver as t };