@vercel/sandbox 2.0.0-beta.11 → 2.0.0-beta.13

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 (196) hide show
  1. package/README.md +8 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  3. package/dist/api-client/api-client.cjs +456 -0
  4. package/dist/api-client/api-client.cjs.map +1 -0
  5. package/dist/api-client/api-client.d.cts +790 -0
  6. package/dist/api-client/api-client.d.ts +784 -777
  7. package/dist/api-client/api-client.js +445 -471
  8. package/dist/api-client/api-client.js.map +1 -1
  9. package/dist/api-client/api-error.cjs +32 -0
  10. package/dist/api-client/api-error.cjs.map +1 -0
  11. package/dist/api-client/api-error.d.cts +29 -0
  12. package/dist/api-client/api-error.d.ts +21 -18
  13. package/dist/api-client/api-error.js +28 -33
  14. package/dist/api-client/api-error.js.map +1 -1
  15. package/dist/api-client/base-client.cjs +125 -0
  16. package/dist/api-client/base-client.cjs.map +1 -0
  17. package/dist/api-client/base-client.d.cts +38 -0
  18. package/dist/api-client/base-client.d.ts +31 -36
  19. package/dist/api-client/base-client.js +110 -130
  20. package/dist/api-client/base-client.js.map +1 -1
  21. package/dist/api-client/file-writer.cjs +62 -0
  22. package/dist/api-client/file-writer.cjs.map +1 -0
  23. package/dist/api-client/file-writer.d.cts +66 -0
  24. package/dist/api-client/file-writer.d.ts +56 -52
  25. package/dist/api-client/file-writer.js +57 -61
  26. package/dist/api-client/file-writer.js.map +1 -1
  27. package/dist/api-client/index.cjs +2 -0
  28. package/dist/api-client/index.d.ts +2 -2
  29. package/dist/api-client/index.js +4 -21
  30. package/dist/api-client/validators.cjs +182 -0
  31. package/dist/api-client/validators.cjs.map +1 -0
  32. package/dist/api-client/validators.d.cts +1469 -0
  33. package/dist/api-client/validators.d.ts +1282 -3699
  34. package/dist/api-client/validators.js +155 -170
  35. package/dist/api-client/validators.js.map +1 -1
  36. package/dist/api-client/with-retry.cjs +89 -0
  37. package/dist/api-client/with-retry.cjs.map +1 -0
  38. package/dist/api-client/with-retry.d.cts +10 -0
  39. package/dist/api-client/with-retry.d.ts +9 -13
  40. package/dist/api-client/with-retry.js +81 -102
  41. package/dist/api-client/with-retry.js.map +1 -1
  42. package/dist/auth/api.cjs +29 -0
  43. package/dist/auth/api.cjs.map +1 -0
  44. package/dist/auth/api.js +26 -25
  45. package/dist/auth/api.js.map +1 -1
  46. package/dist/auth/error.cjs +13 -0
  47. package/dist/auth/error.cjs.map +1 -0
  48. package/dist/auth/error.js +11 -11
  49. package/dist/auth/error.js.map +1 -1
  50. package/dist/auth/file.cjs +64 -0
  51. package/dist/auth/file.cjs.map +1 -0
  52. package/dist/auth/file.d.cts +26 -0
  53. package/dist/auth/file.d.ts +19 -15
  54. package/dist/auth/file.js +49 -64
  55. package/dist/auth/file.js.map +1 -1
  56. package/dist/auth/index.cjs +12 -0
  57. package/dist/auth/index.d.cts +5 -0
  58. package/dist/auth/index.d.ts +5 -6
  59. package/dist/auth/index.js +6 -27
  60. package/dist/auth/linked-project.cjs +38 -0
  61. package/dist/auth/linked-project.cjs.map +1 -0
  62. package/dist/auth/linked-project.js +30 -64
  63. package/dist/auth/linked-project.js.map +1 -1
  64. package/dist/auth/oauth.cjs +205 -0
  65. package/dist/auth/oauth.cjs.map +1 -0
  66. package/dist/auth/oauth.d.cts +135 -0
  67. package/dist/auth/oauth.d.ts +113 -109
  68. package/dist/auth/oauth.js +185 -252
  69. package/dist/auth/oauth.js.map +1 -1
  70. package/dist/auth/poll-for-token.cjs +82 -0
  71. package/dist/auth/poll-for-token.cjs.map +1 -0
  72. package/dist/auth/poll-for-token.d.cts +28 -0
  73. package/dist/auth/poll-for-token.d.ts +23 -15
  74. package/dist/auth/poll-for-token.js +79 -64
  75. package/dist/auth/poll-for-token.js.map +1 -1
  76. package/dist/auth/project.cjs +80 -0
  77. package/dist/auth/project.cjs.map +1 -0
  78. package/dist/auth/project.d.cts +44 -0
  79. package/dist/auth/project.d.ts +12 -8
  80. package/dist/auth/project.js +70 -72
  81. package/dist/auth/project.js.map +1 -1
  82. package/dist/auth/zod.cjs +22 -0
  83. package/dist/auth/zod.cjs.map +1 -0
  84. package/dist/auth/zod.js +18 -17
  85. package/dist/auth/zod.js.map +1 -1
  86. package/dist/command.cjs +328 -0
  87. package/dist/command.cjs.map +1 -0
  88. package/dist/command.d.cts +289 -0
  89. package/dist/command.d.ts +265 -171
  90. package/dist/command.js +323 -226
  91. package/dist/command.js.map +1 -1
  92. package/dist/constants.d.cts +5 -0
  93. package/dist/constants.d.ts +5 -1
  94. package/dist/index.cjs +13 -0
  95. package/dist/index.d.cts +7 -0
  96. package/dist/index.d.ts +7 -6
  97. package/dist/index.js +7 -17
  98. package/dist/network-policy.d.cts +100 -0
  99. package/dist/network-policy.d.ts +32 -28
  100. package/dist/sandbox.cjs +694 -0
  101. package/dist/sandbox.cjs.map +1 -0
  102. package/dist/sandbox.d.cts +796 -0
  103. package/dist/sandbox.d.ts +783 -711
  104. package/dist/sandbox.js +684 -615
  105. package/dist/sandbox.js.map +1 -1
  106. package/dist/session.cjs +520 -0
  107. package/dist/session.cjs.map +1 -0
  108. package/dist/session.d.cts +406 -0
  109. package/dist/session.d.ts +398 -367
  110. package/dist/session.js +517 -505
  111. package/dist/session.js.map +1 -1
  112. package/dist/snapshot.cjs +116 -0
  113. package/dist/snapshot.cjs.map +1 -0
  114. package/dist/snapshot.d.cts +107 -0
  115. package/dist/snapshot.d.ts +98 -91
  116. package/dist/snapshot.js +114 -115
  117. package/dist/snapshot.js.map +1 -1
  118. package/dist/utils/array.cjs +17 -0
  119. package/dist/utils/array.cjs.map +1 -0
  120. package/dist/utils/array.js +12 -15
  121. package/dist/utils/array.js.map +1 -1
  122. package/dist/utils/consume-readable.cjs +18 -0
  123. package/dist/utils/consume-readable.cjs.map +1 -0
  124. package/dist/utils/consume-readable.js +13 -12
  125. package/dist/utils/consume-readable.js.map +1 -1
  126. package/dist/utils/decode-base64-url.cjs +15 -0
  127. package/dist/utils/decode-base64-url.cjs.map +1 -0
  128. package/dist/utils/decode-base64-url.js +10 -9
  129. package/dist/utils/decode-base64-url.js.map +1 -1
  130. package/dist/utils/dev-credentials.cjs +142 -0
  131. package/dist/utils/dev-credentials.cjs.map +1 -0
  132. package/dist/utils/dev-credentials.js +126 -184
  133. package/dist/utils/dev-credentials.js.map +1 -1
  134. package/dist/utils/get-credentials.cjs +123 -0
  135. package/dist/utils/get-credentials.cjs.map +1 -0
  136. package/dist/utils/get-credentials.d.cts +21 -0
  137. package/dist/utils/get-credentials.d.ts +19 -61
  138. package/dist/utils/get-credentials.js +106 -140
  139. package/dist/utils/get-credentials.js.map +1 -1
  140. package/dist/utils/log.cjs +25 -0
  141. package/dist/utils/log.cjs.map +1 -0
  142. package/dist/utils/log.js +15 -17
  143. package/dist/utils/log.js.map +1 -1
  144. package/dist/utils/network-policy.cjs +65 -0
  145. package/dist/utils/network-policy.cjs.map +1 -0
  146. package/dist/utils/network-policy.js +58 -77
  147. package/dist/utils/network-policy.js.map +1 -1
  148. package/dist/utils/normalizePath.cjs +27 -0
  149. package/dist/utils/normalizePath.cjs.map +1 -0
  150. package/dist/utils/normalizePath.js +21 -28
  151. package/dist/utils/normalizePath.js.map +1 -1
  152. package/dist/utils/resolveSignal.cjs +20 -0
  153. package/dist/utils/resolveSignal.cjs.map +1 -0
  154. package/dist/utils/resolveSignal.d.cts +15 -0
  155. package/dist/utils/resolveSignal.d.ts +12 -10
  156. package/dist/utils/resolveSignal.js +14 -17
  157. package/dist/utils/resolveSignal.js.map +1 -1
  158. package/dist/utils/sandbox-snapshot.cjs +14 -0
  159. package/dist/utils/sandbox-snapshot.cjs.map +1 -0
  160. package/dist/utils/sandbox-snapshot.d.cts +10 -0
  161. package/dist/utils/sandbox-snapshot.d.ts +11 -0
  162. package/dist/utils/sandbox-snapshot.js +14 -0
  163. package/dist/utils/sandbox-snapshot.js.map +1 -0
  164. package/dist/utils/types.cjs +13 -0
  165. package/dist/utils/types.cjs.map +1 -0
  166. package/dist/utils/types.d.cts +11 -0
  167. package/dist/utils/types.d.ts +5 -7
  168. package/dist/utils/types.js +8 -8
  169. package/dist/utils/types.js.map +1 -1
  170. package/dist/version.cjs +7 -0
  171. package/dist/version.cjs.map +1 -0
  172. package/dist/version.js +5 -5
  173. package/dist/version.js.map +1 -1
  174. package/package.json +23 -3
  175. package/dist/api-client/index.js.map +0 -1
  176. package/dist/auth/api.d.ts +0 -6
  177. package/dist/auth/error.d.ts +0 -11
  178. package/dist/auth/index.js.map +0 -1
  179. package/dist/auth/linked-project.d.ts +0 -10
  180. package/dist/auth/zod.d.ts +0 -5
  181. package/dist/constants.js +0 -3
  182. package/dist/constants.js.map +0 -1
  183. package/dist/index.js.map +0 -1
  184. package/dist/network-policy.js +0 -3
  185. package/dist/network-policy.js.map +0 -1
  186. package/dist/utils/array.d.ts +0 -9
  187. package/dist/utils/consume-readable.d.ts +0 -5
  188. package/dist/utils/convert-sandbox.d.ts +0 -6
  189. package/dist/utils/convert-sandbox.js +0 -14
  190. package/dist/utils/convert-sandbox.js.map +0 -1
  191. package/dist/utils/decode-base64-url.d.ts +0 -7
  192. package/dist/utils/dev-credentials.d.ts +0 -37
  193. package/dist/utils/log.d.ts +0 -2
  194. package/dist/utils/network-policy.d.ts +0 -7
  195. package/dist/utils/normalizePath.d.ts +0 -17
  196. package/dist/version.d.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":";;;AAKA,6CAAyC;AACzC,sDAAkD;AAClD,6DAA2E;AAC3E,yCAAmE;AAGnE,uCAA2D;AAK3D,2DAA8D;AAC9D,mDAAkD;AAsHlD,SAAS,qBAAqB,CAAC,GAAY;IACzC,OAAO,GAAG,YAAY,oBAAQ,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC;AAChE,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAY;IAC1C,OAAO,CACL,GAAG,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AC,YAAY,CAAC;YAC9C,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,KAAK,EAAE,MAAM,EAAE,KAAK;YACpB,MAAM,EAAE,MAAM,EAAE,MAAM;YACtB,SAAS,EAAE,MAAM,EAAE,SAAS;YAC5B,MAAM,EAAE,MAAM,EAAE,MAAM;SACvB,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,MAKnB;QACC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;YAC/C,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,KAAK,EAAE,MAAM,EAAE,KAAK;YACpB,MAAM,EAAE,MAAM,EAAE,MAAM;YACtB,SAAS,EAAE,MAAM,EAAE,SAAS;YAC5B,MAAM,EAAE,MAAM,EAAE,MAAM;SACvB,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AArxBD,0BAqxBC;AAED;;;;;;;;GAQG;AACH,MAAM,iBAAkB,SAAQ,OAAO;IACrC,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;CACF"}
1
+ {"version":3,"file":"sandbox.js","names":["resources: { vcpus: number; memory: number } | undefined"],"sources":["../src/sandbox.ts"],"sourcesContent":["import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE } from \"@workflow/serde\";\nimport type {\n SessionMetaData,\n SandboxRouteData,\n SandboxMetaData,\n} from \"./api-client/index.js\";\nimport { APIClient } from \"./api-client/index.js\";\nimport { APIError } from \"./api-client/api-error.js\";\nimport { type Credentials, getCredentials } from \"./utils/get-credentials.js\";\nimport { getPrivateParams, type WithPrivate } from \"./utils/types.js\";\nimport type { WithFetchOptions } from \"./api-client/api-client.js\";\nimport type { RUNTIMES } from \"./constants.js\";\nimport { Session, type RunCommandParams } from \"./session.js\";\nimport type { Command, CommandFinished } from \"./command.js\";\nimport type { Snapshot } from \"./snapshot.js\";\nimport type { SandboxSnapshot } from \"./utils/sandbox-snapshot.js\";\nimport type { NetworkPolicy } from \"./network-policy.js\";\nimport { fromAPINetworkPolicy } from \"./utils/network-policy.js\";\nimport { setTimeout } from \"node:timers/promises\";\n\nexport type { NetworkPolicy };\n\n/** @inline */\nexport interface BaseCreateSandboxParams {\n /**\n * The name of the sandbox. If omitted, a random name will be generated.\n */\n name?: string;\n /**\n * The source of the sandbox.\n *\n * Omit this parameter start a sandbox without a source.\n *\n * For git sources:\n * - `depth`: Creates shallow clones with limited commit history (minimum: 1)\n * - `revision`: Clones and checks out a specific commit, branch, or tag\n */\n source?:\n | {\n type: \"git\";\n url: string;\n depth?: number;\n revision?: string;\n }\n | {\n type: \"git\";\n url: string;\n username: string;\n password: string;\n depth?: number;\n revision?: string;\n }\n | { type: \"tarball\"; url: string };\n /**\n * Array of port numbers to expose from the sandbox. Sandboxes can\n * expose up to 4 ports.\n */\n ports?: number[];\n /**\n * Timeout in milliseconds before the sandbox auto-terminates.\n */\n timeout?: number;\n /**\n * Resources to allocate to the sandbox.\n *\n * Your sandbox will get the amount of vCPUs you specify here and\n * 2048 MB of memory per vCPU.\n */\n resources?: { vcpus: number };\n /**\n * The runtime of the sandbox, currently only `node24`, `node22` and `python3.13` are supported.\n * If not specified, the default runtime `node24` will be used.\n */\n runtime?: RUNTIMES | (string & {});\n /**\n * Network policy to define network restrictions for the sandbox.\n * Defaults to full internet access if not specified.\n */\n networkPolicy?: NetworkPolicy;\n /**\n * Default environment variables for the sandbox.\n * These are inherited by all commands unless overridden with\n * the `env` option in `runCommand`.\n *\n * @example\n * const sandbox = await Sandbox.create({\n * env: { NODE_ENV: \"production\", API_KEY: \"secret\" },\n * });\n * // All commands will have NODE_ENV and API_KEY set\n * await sandbox.runCommand(\"node\", [\"app.js\"]);\n */\n env?: Record<string, string>;\n /**\n * Key-value tags to associate with the sandbox. Maximum 5 tags.\n * @example { env: \"staging\", team: \"infra\" }\n */\n tags?: Record<string, string>;\n\n /**\n * An AbortSignal to cancel sandbox creation.\n */\n signal?: AbortSignal;\n /**\n * Enable or disable automatic restore of the filesystem between sessions.\n */\n persistent?: boolean;\n /**\n * Default snapshot expiration in milliseconds.\n * When set, snapshots created for this sandbox will expire after this duration.\n * Use `0` for no expiration.\n */\n snapshotExpiration?: number;\n /**\n * Called when the sandbox session is resumed (e.g., after a snapshot restore).\n * Use this to re-warm caches, restore transient state, or run other setup logic.\n */\n onResume?: (sandbox: Sandbox) => Promise<void>;\n}\n\nexport type CreateSandboxParams =\n | BaseCreateSandboxParams\n | (Omit<BaseCreateSandboxParams, \"runtime\" | \"source\"> & {\n source: { type: \"snapshot\"; snapshotId: string };\n });\n\n/** @inline */\ninterface GetSandboxParams {\n /**\n * The name of the sandbox.\n */\n name: string;\n /**\n * Whether to resume an existing session. Defaults to true.\n */\n resume?: boolean;\n /**\n * An AbortSignal to cancel the operation.\n */\n signal?: AbortSignal;\n /**\n * Called when the sandbox session is resumed (e.g., after a snapshot restore).\n * Use this to re-warm caches, restore transient state, or run other setup logic.\n */\n onResume?: (sandbox: Sandbox) => Promise<void>;\n}\n\nfunction isSandboxStoppedError(err: unknown): boolean {\n return err instanceof APIError && err.response.status === 410;\n}\n\nfunction isSandboxStoppingError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 422 &&\n (err.json as any)?.error?.code === \"sandbox_stopping\"\n );\n}\n\nfunction isSandboxSnapshottingError(err: unknown): boolean {\n return (\n err instanceof APIError &&\n err.response.status === 422 &&\n (err.json as any)?.error?.code === \"sandbox_snapshotting\"\n );\n}\n\n/**\n * Serialized representation of a Sandbox for @workflow/serde.\n * Fields `metadata` and `routes` are the original wire format from main.\n * Fields `sandboxMetadata` and `projectId` are added for named-sandboxes.\n */\nexport interface SerializedSandbox {\n metadata: SandboxSnapshot;\n routes: SandboxRouteData[];\n sandboxMetadata?: SandboxMetaData;\n projectId?: string;\n}\n\n// ============================================================================\n// Sandbox class\n// ============================================================================\n\n/**\n * A Sandbox is a persistent, isolated Linux MicroVMs to run commands in.\n * Use {@link Sandbox.create} or {@link Sandbox.get} to construct.\n * @hideconstructor\n */\nexport class Sandbox {\n private _client: APIClient | null = null;\n private readonly projectId: string;\n\n /**\n * In-flight resume promise, used to deduplicate concurrent resume calls.\n */\n private resumePromise: Promise<void> | null = null;\n\n /**\n * Internal Session instance for the current VM.\n */\n private session: Session | undefined;\n\n /**\n * Internal metadata about the sandbox.\n */\n private sandbox: SandboxMetaData;\n\n /**\n * Hook that will be executed when a new session is created during resume.\n */\n private readonly onResume?: (sandbox: Sandbox) => Promise<void>;\n\n /**\n * Lazily resolve credentials and construct an API client.\n * @internal\n */\n private async ensureClient(): Promise<APIClient> {\n \"use step\";\n if (this._client) return this._client;\n const credentials = await getCredentials();\n this._client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n });\n return this._client;\n }\n\n /**\n * The name of this sandbox.\n */\n public get name(): string {\n return this.sandbox.name;\n }\n\n /**\n * Routes from ports to subdomains.\n * @hidden\n */\n public get routes(): SandboxRouteData[] {\n return this.currentSession().routes;\n }\n\n /**\n * Whether the sandbox persists the state.\n */\n public get persistent(): boolean {\n return this.sandbox.persistent;\n }\n\n /**\n * The region this sandbox runs in.\n */\n public get region(): string | undefined {\n return this.sandbox.region;\n }\n\n /**\n * Number of virtual CPUs allocated.\n */\n public get vcpus(): number | undefined {\n return this.sandbox.vcpus;\n }\n\n /**\n * Memory allocated in MB.\n */\n public get memory(): number | undefined {\n return this.sandbox.memory;\n }\n\n /** Runtime identifier (e.g. \"node24\", \"python3.13\"). */\n public get runtime(): string | undefined {\n return this.sandbox.runtime;\n }\n\n /**\n * Cumulative egress bytes across all sessions.\n */\n public get totalEgressBytes(): number | undefined {\n return this.sandbox.totalEgressBytes;\n }\n\n /**\n * Cumulative ingress bytes across all sessions.\n */\n public get totalIngressBytes(): number | undefined {\n return this.sandbox.totalIngressBytes;\n }\n\n /**\n * Cumulative active CPU duration in milliseconds across all sessions.\n */\n public get totalActiveCpuDurationMs(): number | undefined {\n return this.sandbox.totalActiveCpuDurationMs;\n }\n\n /**\n * Cumulative wall-clock duration in milliseconds across all sessions.\n */\n public get totalDurationMs(): number | undefined {\n return this.sandbox.totalDurationMs;\n }\n\n /**\n * When this sandbox was last updated.\n */\n public get updatedAt(): Date {\n return new Date(this.sandbox.updatedAt);\n }\n\n /**\n * When the sandbox status was last updated.\n */\n public get statusUpdatedAt(): Date | undefined {\n return this.sandbox.statusUpdatedAt\n ? new Date(this.sandbox.statusUpdatedAt)\n : undefined;\n }\n\n /**\n * When this sandbox was created.\n */\n public get createdAt(): Date {\n return new Date(this.sandbox.createdAt);\n }\n\n /**\n * Interactive port.\n */\n public get interactivePort(): number | undefined {\n return this.currentSession().interactivePort;\n }\n\n /**\n * The status of the current session.\n */\n public get status(): SessionMetaData[\"status\"] {\n return this.currentSession().status;\n }\n\n /**\n * The default timeout of this sandbox in milliseconds.\n */\n public get timeout(): number | undefined {\n return this.sandbox.timeout;\n }\n\n /**\n * Key-value tags attached to the sandbox.\n */\n public get tags(): Record<string, string> | undefined {\n return this.sandbox.tags;\n }\n\n /**\n * The default network policy of this sandbox.\n */\n public get networkPolicy(): NetworkPolicy | undefined {\n return this.sandbox.networkPolicy\n ? fromAPINetworkPolicy(this.sandbox.networkPolicy)\n : undefined;\n }\n\n /**\n * If the session was created from a snapshot, the ID of that snapshot.\n */\n public get sourceSnapshotId(): string | undefined {\n return this.currentSession().sourceSnapshotId;\n }\n\n /**\n * The current snapshot ID of this sandbox, if any.\n */\n public get currentSnapshotId(): string | undefined {\n return this.sandbox.currentSnapshotId;\n }\n\n /**\n * The default snapshot expiration in milliseconds, if set.\n */\n public get snapshotExpiration(): number | undefined {\n return this.sandbox.snapshotExpiration;\n }\n\n /**\n * The amount of CPU used by the session. Only reported once the VM is stopped.\n */\n public get activeCpuUsageMs(): number | undefined {\n return this.currentSession().activeCpuUsageMs;\n }\n\n /**\n * The amount of network data used by the session. Only reported once the VM is stopped.\n */\n public get networkTransfer():\n | { ingress: number; egress: number }\n | undefined {\n return this.currentSession().networkTransfer;\n }\n\n /**\n * Allow to get a list of sandboxes for a team narrowed to the given params.\n * It returns both the sandboxes and the pagination metadata to allow getting\n * the next page of results.\n */\n static async list(\n params?: Partial<Parameters<APIClient[\"listSandboxes\"]>[0]> &\n Partial<Credentials> &\n WithFetchOptions,\n ) {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n const response = await client.listSandboxes({\n ...credentials,\n ...params,\n });\n return response.json;\n }\n\n /**\n * Serialize a Sandbox instance to plain data for @workflow/serde.\n *\n * @param instance - The Sandbox instance to serialize\n * @returns A plain object containing sandbox metadata and routes\n */\n static [WORKFLOW_SERIALIZE](instance: Sandbox): SerializedSandbox {\n return {\n metadata: instance.session?._sessionSnapshot!,\n routes: instance.session?.routes ?? [],\n sandboxMetadata: instance.sandbox,\n projectId: instance.projectId,\n };\n }\n\n /**\n * Deserialize a Sandbox from serialized snapshot data.\n *\n * The deserialized instance uses the serialized metadata synchronously and\n * lazily creates an API client only when methods perform API requests.\n *\n * @param data - The serialized sandbox data\n * @returns The reconstructed Sandbox instance\n */\n static [WORKFLOW_DESERIALIZE](data: SerializedSandbox): Sandbox {\n const sandbox = new Sandbox({\n sandbox: data.sandboxMetadata!,\n routes: data.routes,\n projectId: data.projectId,\n });\n if (data.metadata) {\n sandbox.session = new Session({ routes: data.routes, snapshot: data.metadata });\n }\n return sandbox;\n }\n\n /**\n * Create a new sandbox.\n *\n * @param params - Creation parameters and optional credentials.\n * @returns A promise resolving to the created {@link Sandbox}.\n * @example\n * <caption>Create a sandbox with default options</caption>\n * const sandbox = await Sandbox.create();\n *\n * @example\n * <caption>Create a sandbox and drop it in the end of the block</caption>\n * async function fn() {\n * await using const sandbox = await Sandbox.create();\n * // Sandbox automatically stopped at the end of the lexical scope\n * }\n */\n static async create(\n params?: WithPrivate<\n CreateSandboxParams | (CreateSandboxParams & Credentials)\n > &\n WithFetchOptions,\n ): Promise<Sandbox & AsyncDisposable> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params?.fetch,\n });\n\n const privateParams = getPrivateParams(params);\n const response = await client.createSandbox({\n source: params?.source,\n projectId: credentials.projectId,\n ports: params?.ports ?? [],\n timeout: params?.timeout,\n resources: params?.resources,\n runtime: params && \"runtime\" in params ? params?.runtime : undefined,\n networkPolicy: params?.networkPolicy,\n env: params?.env,\n tags: params?.tags,\n snapshotExpiration: params?.snapshotExpiration,\n signal: params?.signal,\n name: params?.name,\n persistent: params?.persistent,\n ...privateParams,\n });\n\n return new DisposableSandbox({\n client,\n session: response.json.session,\n sandbox: response.json.sandbox,\n routes: response.json.routes,\n projectId: credentials.projectId,\n onResume: params?.onResume,\n });\n }\n\n /**\n * Retrieve an existing sandbox and resume its session.\n *\n * @param params - Get parameters and optional credentials.\n * @returns A promise resolving to the {@link Sandbox}.\n */\n static async get(\n params: WithPrivate<GetSandboxParams | (GetSandboxParams & Credentials)> &\n WithFetchOptions,\n ): Promise<Sandbox> {\n \"use step\";\n const credentials = await getCredentials(params);\n const client = new APIClient({\n teamId: credentials.teamId,\n token: credentials.token,\n fetch: params.fetch,\n });\n\n const privateParams = getPrivateParams(params);\n const response = await client.getSandbox({\n name: params.name,\n projectId: credentials.projectId,\n resume: params.resume,\n signal: params.signal,\n ...privateParams,\n });\n\n const sandbox = new Sandbox({\n client,\n session: response.json.session,\n sandbox: response.json.sandbox,\n routes: response.json.routes,\n projectId: credentials.projectId,\n onResume: params.onResume,\n });\n\n if (response.json.resumed && params.onResume) {\n await params.onResume(sandbox);\n }\n\n return sandbox;\n }\n\n /**\n * Create a new Sandbox instance.\n *\n * @param params.client - Optional API client. If not provided, will be lazily created using global credentials.\n * @param params.routes - Port-to-subdomain mappings for exposed ports\n * @param params.sandbox - Sandbox snapshot metadata\n */\n constructor({\n client,\n routes,\n session,\n sandbox,\n projectId,\n onResume,\n }: {\n client?: APIClient;\n routes: SandboxRouteData[];\n session?: SessionMetaData;\n sandbox: SandboxMetaData;\n projectId?: string;\n onResume?: (sandbox: Sandbox) => Promise<void>;\n }) {\n this._client = client ?? null;\n if (session) {\n this.session = new Session({ client: client!, routes, session });\n }\n this.sandbox = sandbox;\n this.projectId = projectId ?? \"\";\n this.onResume = onResume;\n }\n\n /**\n * Get the current session (the running VM) for this sandbox.\n *\n * @returns The {@link Session} instance.\n */\n currentSession(): Session {\n if (!this.session) {\n throw new Error(\"No active session. Run a command or call resume first.\");\n }\n return this.session;\n }\n\n /**\n * Resume this sandbox by creating a new session via `getSandbox`.\n */\n private async resume(signal?: AbortSignal): Promise<void> {\n if (!this.resumePromise) {\n this.resumePromise = this.doResume(signal).finally(() => {\n this.resumePromise = null;\n });\n }\n return this.resumePromise;\n }\n\n private async doResume(signal?: AbortSignal): Promise<void> {\n const client = await this.ensureClient();\n const response = await client.getSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n resume: true,\n signal,\n });\n this.session = new Session({\n client,\n routes: response.json.routes,\n session: response.json.session,\n });\n if (this.onResume && response.json.resumed) {\n await this.onResume(this);\n }\n }\n\n /**\n * Poll until the current session reaches a terminal state, then resume.\n */\n private async waitForStopAndResume(signal?: AbortSignal): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n const pollingInterval = 500;\n let status = this.session!.status;\n\n while (status === \"stopping\" || status === \"snapshotting\") {\n await setTimeout(pollingInterval, undefined, { signal });\n const poll = await client.getSession({\n sessionId: this.session!.sessionId,\n signal,\n });\n this.session = new Session({\n client,\n routes: poll.json.routes,\n session: poll.json.session,\n });\n status = poll.json.session.status;\n }\n await this.resume(signal);\n }\n\n /**\n * Execute `fn`, and if the session is stopped/stopping/snapshotting, resume and retry.\n */\n private async withResume<T>(\n fn: () => Promise<T>,\n signal?: AbortSignal,\n ): Promise<T> {\n if (!this.session) {\n await this.resume(signal);\n }\n try {\n return await fn();\n } catch (err) {\n if (isSandboxStoppedError(err)) {\n await this.resume(signal);\n return fn();\n }\n if (isSandboxStoppingError(err) || isSandboxSnapshottingError(err)) {\n await this.waitForStopAndResume(signal);\n return fn();\n }\n throw err;\n }\n }\n\n /**\n * Start executing a command in this sandbox.\n *\n * @param command - The command to execute.\n * @param args - Arguments to pass to the command.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the command execution.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n async runCommand(\n command: string,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<CommandFinished>;\n /**\n * Start executing a command in detached mode.\n *\n * @param params - The command parameters.\n * @returns A {@link Command} instance for the running command.\n */\n async runCommand(\n params: RunCommandParams & { detached: true },\n ): Promise<Command>;\n\n /**\n * Start executing a command in this sandbox.\n *\n * @param params - The command parameters.\n * @returns A {@link CommandFinished} result once execution is done.\n */\n\n async runCommand(params: RunCommandParams): Promise<CommandFinished>;\n\n async runCommand(\n commandOrParams: string | RunCommandParams,\n args?: string[],\n opts?: { signal?: AbortSignal },\n ): Promise<Command | CommandFinished> {\n \"use step\";\n const signal =\n typeof commandOrParams === \"string\"\n ? opts?.signal\n : commandOrParams.signal;\n return this.withResume(\n () => this.session!.runCommand(commandOrParams as any, args, opts),\n signal,\n );\n }\n\n /**\n * Internal helper to start a command in the sandbox.\n *\n * @param params - Command execution parameters.\n * @returns A {@link Command} or {@link CommandFinished}, depending on `detached`.\n * @internal\n */\n async getCommand(\n cmdId: string,\n opts?: { signal?: AbortSignal },\n ): Promise<Command> {\n \"use step\";\n return this.withResume(\n () => this.session!.getCommand(cmdId, opts),\n opts?.signal,\n );\n }\n\n /**\n * Create a directory in the filesystem of this sandbox.\n *\n * @param path - Path of the directory to create\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n */\n async mkDir(path: string, opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n return this.withResume(\n () => this.session!.mkDir(path, opts),\n opts?.signal,\n );\n }\n\n /**\n * Read a file from the filesystem of this sandbox as a stream.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found\n */\n async readFile(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<NodeJS.ReadableStream | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.readFile(file, opts),\n opts?.signal,\n );\n }\n\n /**\n * Read a file from the filesystem of this sandbox as a Buffer.\n *\n * @param file - File to read, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the file contents as a Buffer, or null if file not found\n */\n async readFileToBuffer(\n file: { path: string; cwd?: string },\n opts?: { signal?: AbortSignal },\n ): Promise<Buffer | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.readFileToBuffer(file, opts),\n opts?.signal,\n );\n }\n\n /**\n * Download a file from the sandbox to the local filesystem.\n *\n * @param src - Source file on the sandbox, with path and optional cwd\n * @param dst - Destination file on the local machine, with path and optional cwd\n * @param opts - Optional parameters.\n * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns The absolute path to the written file, or null if the source file was not found\n */\n async downloadFile(\n src: { path: string; cwd?: string },\n dst: { path: string; cwd?: string },\n opts?: { mkdirRecursive?: boolean; signal?: AbortSignal },\n ): Promise<string | null> {\n \"use step\";\n return this.withResume(\n () => this.session!.downloadFile(src, dst, opts),\n opts?.signal,\n );\n }\n\n /**\n * Write files to the filesystem of this sandbox.\n * Defaults to writing to /vercel/sandbox unless an absolute path is specified.\n * Writes files using the `vercel-sandbox` user.\n *\n * @param files - Array of files with path, content, and optional mode (permissions)\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the files are written\n *\n * @example\n * // Write an executable script\n * await sandbox.writeFiles([\n * { path: \"/usr/local/bin/myscript\", content: \"#!/bin/bash\\necho hello\", mode: 0o755 }\n * ]);\n */\n async writeFiles(\n files: {\n path: string;\n content: string | Uint8Array;\n mode?: number;\n }[],\n opts?: { signal?: AbortSignal },\n ) {\n \"use step\";\n return this.withResume(\n () => this.session!.writeFiles(files, opts),\n opts?.signal,\n );\n }\n\n /**\n * Get the public domain of a port of this sandbox.\n *\n * @param p - Port number to resolve\n * @returns A full domain (e.g. `https://subdomain.vercel.run`)\n * @throws If the port has no associated route\n */\n domain(p: number): string {\n return this.currentSession().domain(p);\n }\n\n /**\n * Stop the sandbox.\n *\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @param opts.blocking - If true, poll until the sandbox has fully stopped and return the final state.\n * @returns The sandbox at the time the stop was acknowledged, or after fully stopped if `blocking` is true.\n */\n async stop(opts?: {\n signal?: AbortSignal;\n blocking?: boolean;\n }): Promise<SandboxSnapshot> {\n \"use step\";\n if (!this.session) {\n throw new Error(\"No active session to stop.\");\n }\n return this.session.stop(opts);\n }\n\n /**\n * Update the network policy for this sandbox.\n *\n * @deprecated Use {@link Sandbox.update} instead.\n *\n * @param networkPolicy - The new network policy to apply.\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the network policy is updated.\n *\n * @example\n * // Restrict to specific domains\n * await sandbox.updateNetworkPolicy({\n * allow: [\"*.npmjs.org\", \"github.com\"],\n * });\n *\n * @example\n * // Inject credentials with per-domain transformers\n * await sandbox.updateNetworkPolicy({\n * allow: {\n * \"ai-gateway.vercel.sh\": [{\n * transform: [{\n * headers: { authorization: \"Bearer ...\" }\n * }]\n * }],\n * \"*\": []\n * }\n * });\n *\n * @example\n * // Deny all network access\n * await sandbox.updateNetworkPolicy(\"deny-all\");\n */\n async updateNetworkPolicy(\n networkPolicy: NetworkPolicy,\n opts?: { signal?: AbortSignal },\n ): Promise<NetworkPolicy> {\n \"use step\";\n await this.withResume(\n () => this.session!.update({ networkPolicy: networkPolicy }, opts),\n opts?.signal,\n );\n\n return this.session!.networkPolicy!;\n }\n\n /**\n * Extend the timeout of the sandbox by the specified duration.\n *\n * This allows you to extend the lifetime of a sandbox up until the maximum\n * execution timeout for your plan.\n *\n * @param duration - The duration in milliseconds to extend the timeout by\n * @param opts - Optional parameters.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves when the timeout is extended\n *\n * @example\n * const sandbox = await Sandbox.create({ timeout: ms('10m') });\n * // Extends timeout by 5 minutes, to a total of 15 minutes.\n * await sandbox.extendTimeout(ms('5m'));\n */\n async extendTimeout(\n duration: number,\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n return this.withResume(\n () => this.session!.extendTimeout(duration, opts),\n opts?.signal,\n );\n }\n\n /**\n * Create a snapshot from this currently running sandbox. New sandboxes can\n * then be created from this snapshot using {@link Sandbox.createFromSnapshot}.\n *\n * Note: this sandbox will be stopped as part of the snapshot creation process.\n *\n * @param opts - Optional parameters.\n * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.\n * @param opts.signal - An AbortSignal to cancel the operation.\n * @returns A promise that resolves to the Snapshot instance\n */\n async snapshot(opts?: {\n expiration?: number;\n signal?: AbortSignal;\n }): Promise<Snapshot> {\n \"use step\";\n return this.withResume(\n () => this.session!.snapshot(opts),\n opts?.signal,\n );\n }\n\n /**\n * Update the sandbox configuration.\n *\n * @param params - Fields to update.\n * @param opts - Optional abort signal.\n */\n async update(\n params: {\n persistent?: boolean;\n resources?: { vcpus?: number };\n timeout?: number;\n networkPolicy?: NetworkPolicy;\n tags?: Record<string, string>;\n snapshotExpiration?: number;\n },\n opts?: { signal?: AbortSignal },\n ): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n let resources: { vcpus: number; memory: number } | undefined;\n if (params.resources?.vcpus) {\n resources = {\n vcpus: params.resources.vcpus,\n memory: params.resources.vcpus * 2048,\n };\n }\n\n // Update the sandbox config. This config will be used on the next session.\n const response = await client.updateSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n persistent: params.persistent,\n resources,\n timeout: params.timeout,\n networkPolicy: params.networkPolicy,\n tags: params.tags,\n snapshotExpiration: params.snapshotExpiration,\n signal: opts?.signal,\n });\n this.sandbox = response.json.sandbox;\n\n // Update the current session config. This only applies to network policy.\n if (params.networkPolicy) {\n try {\n return await this.session?.update(\n { networkPolicy: params.networkPolicy },\n opts,\n );\n } catch (err) {\n if (isSandboxStoppedError(err) || isSandboxStoppingError(err)) {\n return;\n }\n throw err;\n }\n }\n }\n\n /**\n * Delete this sandbox.\n *\n * After deletion the instance becomes inert — all further API calls will\n * throw immediately.\n */\n async delete(opts?: { signal?: AbortSignal }): Promise<void> {\n \"use step\";\n const client = await this.ensureClient();\n await client.deleteSandbox({\n name: this.sandbox.name,\n projectId: this.projectId,\n signal: opts?.signal,\n });\n }\n\n /**\n * List sessions (VMs) that have been created for this sandbox.\n *\n * @param params - Optional pagination parameters.\n * @returns The list of sessions and pagination metadata.\n */\n async listSessions(params?: {\n limit?: number;\n cursor?: string;\n sortOrder?: \"asc\" | \"desc\";\n signal?: AbortSignal;\n }) {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.listSessions({\n projectId: this.projectId,\n name: this.sandbox.name,\n limit: params?.limit,\n cursor: params?.cursor,\n sortOrder: params?.sortOrder,\n signal: params?.signal,\n });\n return response.json;\n }\n\n /**\n * List snapshots that belong to this sandbox.\n *\n * @param params - Optional pagination parameters.\n * @returns The list of snapshots and pagination metadata.\n */\n async listSnapshots(params?: {\n limit?: number;\n cursor?: string;\n sortOrder?: \"asc\" | \"desc\";\n signal?: AbortSignal;\n }) {\n \"use step\";\n const client = await this.ensureClient();\n const response = await client.listSnapshots({\n projectId: this.projectId,\n name: this.sandbox.name,\n limit: params?.limit,\n cursor: params?.cursor,\n sortOrder: params?.sortOrder,\n signal: params?.signal,\n });\n return response.json;\n }\n}\n\n/**\n * A {@link Sandbox} that can automatically be disposed using a `await using` statement.\n *\n * @example\n * {\n * await using const sandbox = await Sandbox.create();\n * }\n * // Sandbox is automatically stopped here\n */\nclass DisposableSandbox extends Sandbox implements AsyncDisposable {\n async [Symbol.asyncDispose]() {\n await this.stop();\n }\n}\n"],"mappings":";;;;;;;;;;;AAkJA,SAAS,sBAAsB,KAAuB;AACpD,QAAO,eAAe,YAAY,IAAI,SAAS,WAAW;;AAG5D,SAAS,uBAAuB,KAAuB;AACrD,QACE,eAAe,YACf,IAAI,SAAS,WAAW,OACvB,IAAI,MAAc,OAAO,SAAS;;AAIvC,SAAS,2BAA2B,KAAuB;AACzD,QACE,eAAe,YACf,IAAI,SAAS,WAAW,OACvB,IAAI,MAAc,OAAO,SAAS;;;;;;;AAyBvC,IAAa,UAAb,MAAa,QAAQ;;;;;CA4BnB,MAAc,eAAmC;AAC/C;AACA,MAAI,KAAK,QAAS,QAAO,KAAK;EAC9B,MAAM,cAAc,MAAM,gBAAgB;AAC1C,OAAK,UAAU,IAAI,UAAU;GAC3B,QAAQ,YAAY;GACpB,OAAO,YAAY;GACpB,CAAC;AACF,SAAO,KAAK;;;;;CAMd,IAAW,OAAe;AACxB,SAAO,KAAK,QAAQ;;;;;;CAOtB,IAAW,SAA6B;AACtC,SAAO,KAAK,gBAAgB,CAAC;;;;;CAM/B,IAAW,aAAsB;AAC/B,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,SAA6B;AACtC,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,QAA4B;AACrC,SAAO,KAAK,QAAQ;;;;;CAMtB,IAAW,SAA6B;AACtC,SAAO,KAAK,QAAQ;;;CAItB,IAAW,UAA8B;AACvC,SAAO,KAAK,QAAQ;;;;;CA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M,KAAK,MAAM"}
@@ -0,0 +1,520 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_consume_readable = require('./utils/consume-readable.cjs');
3
+ const require_api_client = require('./api-client/api-client.cjs');
4
+ require('./api-client/index.cjs');
5
+ const require_get_credentials = require('./utils/get-credentials.cjs');
6
+ const require_command = require('./command.cjs');
7
+ const require_snapshot = require('./snapshot.cjs');
8
+ const require_sandbox_snapshot = require('./utils/sandbox-snapshot.cjs');
9
+ let __workflow_serde = require("@workflow/serde");
10
+ let path = require("path");
11
+ let stream_promises = require("stream/promises");
12
+ let fs = require("fs");
13
+ let fs_promises = require("fs/promises");
14
+
15
+ //#region src/session.ts
16
+ /**
17
+ * A Session represents a running VM instance within a {@link Sandbox}.
18
+ *
19
+ * Obtain a session via {@link Sandbox.currentSession}.
20
+ */
21
+ var Session = class Session {
22
+ /**
23
+ * Lazily resolve credentials and construct an API client.
24
+ * This is used in step contexts where the Sandbox was deserialized
25
+ * without a client (e.g. when crossing workflow/step boundaries).
26
+ * Uses getCredentials() which resolves from OIDC or env vars.
27
+ * @internal
28
+ */
29
+ async ensureClient() {
30
+ "use step";
31
+ if (this._client) return this._client;
32
+ const credentials = await require_get_credentials.getCredentials();
33
+ this._client = new require_api_client.APIClient({
34
+ teamId: credentials.teamId,
35
+ token: credentials.token
36
+ });
37
+ return this._client;
38
+ }
39
+ get client() {
40
+ if (!this._client) throw new Error("API client not initialized");
41
+ return this._client;
42
+ }
43
+ /** @internal */
44
+ get _sessionSnapshot() {
45
+ return this.session;
46
+ }
47
+ /**
48
+ * Unique ID of this session.
49
+ */
50
+ get sessionId() {
51
+ return this.session.id;
52
+ }
53
+ get interactivePort() {
54
+ return this.session.interactivePort ?? void 0;
55
+ }
56
+ /**
57
+ * The status of this session.
58
+ */
59
+ get status() {
60
+ return this.session.status;
61
+ }
62
+ /**
63
+ * The creation date of this session.
64
+ */
65
+ get createdAt() {
66
+ return new Date(this.session.createdAt);
67
+ }
68
+ /**
69
+ * The timeout of this session in milliseconds.
70
+ */
71
+ get timeout() {
72
+ return this.session.timeout;
73
+ }
74
+ /**
75
+ * The network policy of this session.
76
+ */
77
+ get networkPolicy() {
78
+ return this.session.networkPolicy;
79
+ }
80
+ /**
81
+ * If the session was created from a snapshot, the ID of that snapshot.
82
+ */
83
+ get sourceSnapshotId() {
84
+ return this.session.sourceSnapshotId;
85
+ }
86
+ /**
87
+ * Memory allocated to this session in MB.
88
+ */
89
+ get memory() {
90
+ return this.session.memory;
91
+ }
92
+ /**
93
+ * Number of vCPUs allocated to this session.
94
+ */
95
+ get vcpus() {
96
+ return this.session.vcpus;
97
+ }
98
+ /**
99
+ * The region where this session is hosted.
100
+ */
101
+ get region() {
102
+ return this.session.region;
103
+ }
104
+ /**
105
+ * Runtime identifier (e.g. "node24", "python3.13").
106
+ */
107
+ get runtime() {
108
+ return this.session.runtime;
109
+ }
110
+ /**
111
+ * The working directory of this session.
112
+ */
113
+ get cwd() {
114
+ return this.session.cwd;
115
+ }
116
+ /**
117
+ * When this session was requested.
118
+ */
119
+ get requestedAt() {
120
+ return new Date(this.session.requestedAt);
121
+ }
122
+ /**
123
+ * When this session started running.
124
+ */
125
+ get startedAt() {
126
+ return this.session.startedAt != null ? new Date(this.session.startedAt) : void 0;
127
+ }
128
+ /**
129
+ * When this session was requested to stop.
130
+ */
131
+ get requestedStopAt() {
132
+ return this.session.requestedStopAt != null ? new Date(this.session.requestedStopAt) : void 0;
133
+ }
134
+ /**
135
+ * When this session was stopped.
136
+ */
137
+ get stoppedAt() {
138
+ return this.session.stoppedAt != null ? new Date(this.session.stoppedAt) : void 0;
139
+ }
140
+ /**
141
+ * When this session was aborted.
142
+ */
143
+ get abortedAt() {
144
+ return this.session.abortedAt != null ? new Date(this.session.abortedAt) : void 0;
145
+ }
146
+ /**
147
+ * The wall-clock duration of this session in milliseconds.
148
+ */
149
+ get duration() {
150
+ return this.session.duration;
151
+ }
152
+ /**
153
+ * When a snapshot was requested for this session.
154
+ */
155
+ get snapshottedAt() {
156
+ return this.session.snapshottedAt != null ? new Date(this.session.snapshottedAt) : void 0;
157
+ }
158
+ /**
159
+ * When this session was last updated.
160
+ */
161
+ get updatedAt() {
162
+ return new Date(this.session.updatedAt);
163
+ }
164
+ /**
165
+ * The amount of active CPU used by the session. Only reported once the VM is
166
+ * stopped.
167
+ */
168
+ get activeCpuUsageMs() {
169
+ return this.session.activeCpuDurationMs;
170
+ }
171
+ /**
172
+ * The amount of network data used by the session. Only reported once the VM
173
+ * is stopped.
174
+ */
175
+ get networkTransfer() {
176
+ return this.session.networkTransfer;
177
+ }
178
+ /**
179
+ * Serialize a Session instance to plain data for @workflow/serde.
180
+ *
181
+ * Although Sandbox handles top-level serialization, Session needs these
182
+ * methods so the Workflow SWC compiler can resolve the class by name.
183
+ * The `new Session(...)` self-reference in WORKFLOW_DESERIALIZE forces
184
+ * rolldown to preserve the class name in the compiled output.
185
+ */
186
+ static [__workflow_serde.WORKFLOW_SERIALIZE](instance) {
187
+ return {
188
+ session: instance.session,
189
+ routes: instance.routes
190
+ };
191
+ }
192
+ static [__workflow_serde.WORKFLOW_DESERIALIZE](data) {
193
+ return new Session({
194
+ routes: data.routes,
195
+ snapshot: data.session
196
+ });
197
+ }
198
+ constructor(params) {
199
+ this._client = null;
200
+ this.routes = params.routes;
201
+ if ("snapshot" in params) this.session = params.snapshot;
202
+ else {
203
+ this._client = params.client;
204
+ this.session = require_sandbox_snapshot.toSandboxSnapshot(params.session);
205
+ }
206
+ }
207
+ /**
208
+ * Get a previously run command by its ID.
209
+ *
210
+ * @param cmdId - ID of the command to retrieve
211
+ * @param opts - Optional parameters.
212
+ * @param opts.signal - An AbortSignal to cancel the operation.
213
+ * @returns A {@link Command} instance representing the command
214
+ */
215
+ async getCommand(cmdId, opts) {
216
+ "use step";
217
+ const client = await this.ensureClient();
218
+ const command = await client.getCommand({
219
+ sessionId: this.session.id,
220
+ cmdId,
221
+ signal: opts?.signal
222
+ });
223
+ return new require_command.Command({
224
+ client,
225
+ sessionId: this.session.id,
226
+ cmd: command.json.command
227
+ });
228
+ }
229
+ async runCommand(commandOrParams, args, opts) {
230
+ "use step";
231
+ const client = await this.ensureClient();
232
+ const params = typeof commandOrParams === "string" ? {
233
+ cmd: commandOrParams,
234
+ args,
235
+ signal: opts?.signal
236
+ } : commandOrParams;
237
+ const wait = params.detached ? false : true;
238
+ const pipeLogs = async (command$1) => {
239
+ if (!params.stdout && !params.stderr) return;
240
+ try {
241
+ for await (const log of command$1.logs({ signal: params.signal })) if (log.stream === "stdout") params.stdout?.write(log.data);
242
+ else if (log.stream === "stderr") params.stderr?.write(log.data);
243
+ } catch (err) {
244
+ if (params.signal?.aborted) return;
245
+ throw err;
246
+ }
247
+ };
248
+ if (wait) {
249
+ const commandStream = await client.runCommand({
250
+ sessionId: this.session.id,
251
+ command: params.cmd,
252
+ args: params.args ?? [],
253
+ cwd: params.cwd,
254
+ env: params.env ?? {},
255
+ sudo: params.sudo ?? false,
256
+ wait: true,
257
+ signal: params.signal
258
+ });
259
+ const command$1 = new require_command.Command({
260
+ client,
261
+ sessionId: this.session.id,
262
+ cmd: commandStream.command
263
+ });
264
+ const [finished] = await Promise.all([commandStream.finished, pipeLogs(command$1)]);
265
+ return new require_command.CommandFinished({
266
+ client,
267
+ sessionId: this.session.id,
268
+ cmd: finished,
269
+ exitCode: finished.exitCode ?? 0
270
+ });
271
+ }
272
+ const commandResponse = await client.runCommand({
273
+ sessionId: this.session.id,
274
+ command: params.cmd,
275
+ args: params.args ?? [],
276
+ cwd: params.cwd,
277
+ env: params.env ?? {},
278
+ sudo: params.sudo ?? false,
279
+ signal: params.signal
280
+ });
281
+ const command = new require_command.Command({
282
+ client,
283
+ sessionId: this.session.id,
284
+ cmd: commandResponse.json.command
285
+ });
286
+ pipeLogs(command).catch((err) => {
287
+ if (params.signal?.aborted) return;
288
+ (params.stderr ?? params.stdout)?.emit("error", err);
289
+ });
290
+ return command;
291
+ }
292
+ /**
293
+ * Create a directory in the filesystem of this session.
294
+ *
295
+ * @param path - Path of the directory to create
296
+ * @param opts - Optional parameters.
297
+ * @param opts.signal - An AbortSignal to cancel the operation.
298
+ */
299
+ async mkDir(path$1, opts) {
300
+ "use step";
301
+ await (await this.ensureClient()).mkDir({
302
+ sessionId: this.session.id,
303
+ path: path$1,
304
+ signal: opts?.signal
305
+ });
306
+ }
307
+ /**
308
+ * Read a file from the filesystem of this session as a stream.
309
+ *
310
+ * @param file - File to read, with path and optional cwd
311
+ * @param opts - Optional parameters.
312
+ * @param opts.signal - An AbortSignal to cancel the operation.
313
+ * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found
314
+ */
315
+ async readFile(file, opts) {
316
+ "use step";
317
+ return (await this.ensureClient()).readFile({
318
+ sessionId: this.session.id,
319
+ path: file.path,
320
+ cwd: file.cwd,
321
+ signal: opts?.signal
322
+ });
323
+ }
324
+ /**
325
+ * Read a file from the filesystem of this session as a Buffer.
326
+ *
327
+ * @param file - File to read, with path and optional cwd
328
+ * @param opts - Optional parameters.
329
+ * @param opts.signal - An AbortSignal to cancel the operation.
330
+ * @returns A promise that resolves to the file contents as a Buffer, or null if file not found
331
+ */
332
+ async readFileToBuffer(file, opts) {
333
+ "use step";
334
+ const stream = await (await this.ensureClient()).readFile({
335
+ sessionId: this.session.id,
336
+ path: file.path,
337
+ cwd: file.cwd,
338
+ signal: opts?.signal
339
+ });
340
+ if (stream === null) return null;
341
+ return require_consume_readable.consumeReadable(stream);
342
+ }
343
+ /**
344
+ * Download a file from the session to the local filesystem.
345
+ *
346
+ * @param src - Source file on the session, with path and optional cwd
347
+ * @param dst - Destination file on the local machine, with path and optional cwd
348
+ * @param opts - Optional parameters.
349
+ * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.
350
+ * @param opts.signal - An AbortSignal to cancel the operation.
351
+ * @returns The absolute path to the written file, or null if the source file was not found
352
+ */
353
+ async downloadFile(src, dst, opts) {
354
+ "use step";
355
+ const client = await this.ensureClient();
356
+ if (!src?.path) throw new Error("downloadFile: source path is required");
357
+ if (!dst?.path) throw new Error("downloadFile: destination path is required");
358
+ const stream = await client.readFile({
359
+ sessionId: this.session.id,
360
+ path: src.path,
361
+ cwd: src.cwd,
362
+ signal: opts?.signal
363
+ });
364
+ if (stream === null) return null;
365
+ try {
366
+ const dstPath = (0, path.resolve)(dst.cwd ?? "", dst.path);
367
+ if (opts?.mkdirRecursive) await (0, fs_promises.mkdir)((0, path.dirname)(dstPath), { recursive: true });
368
+ await (0, stream_promises.pipeline)(stream, (0, fs.createWriteStream)(dstPath), { signal: opts?.signal });
369
+ return dstPath;
370
+ } finally {
371
+ stream.destroy();
372
+ }
373
+ }
374
+ /**
375
+ * Write files to the filesystem of this session.
376
+ * Defaults to writing to /vercel/sandbox unless an absolute path is specified.
377
+ * Writes files using the `vercel-sandbox` user.
378
+ *
379
+ * @param files - Array of files with path and stream/buffer contents
380
+ * @param opts - Optional parameters.
381
+ * @param opts.signal - An AbortSignal to cancel the operation.
382
+ * @returns A promise that resolves when the files are written
383
+ */
384
+ async writeFiles(files, opts) {
385
+ "use step";
386
+ return (await this.ensureClient()).writeFiles({
387
+ sessionId: this.session.id,
388
+ cwd: this.session.cwd,
389
+ extractDir: "/",
390
+ files,
391
+ signal: opts?.signal
392
+ });
393
+ }
394
+ /**
395
+ * Get the public domain of a port of this session.
396
+ *
397
+ * @param p - Port number to resolve
398
+ * @returns A full domain (e.g. `https://subdomain.vercel.run`)
399
+ * @throws If the port has no associated route
400
+ */
401
+ domain(p) {
402
+ const route = this.routes.find(({ port }) => port == p);
403
+ if (route) return `https://${route.subdomain}.vercel.run`;
404
+ else throw new Error(`No route for port ${p}`);
405
+ }
406
+ /**
407
+ * Stop this session.
408
+ *
409
+ * @param opts - Optional parameters.
410
+ * @param opts.signal - An AbortSignal to cancel the operation.
411
+ * @param opts.blocking - If true, poll until the session has fully stopped and return the final state.
412
+ * @returns The session at the time the stop was acknowledged, or after fully stopped if `blocking` is true.
413
+ */
414
+ async stop(opts) {
415
+ "use step";
416
+ this.session = require_sandbox_snapshot.toSandboxSnapshot((await (await this.ensureClient()).stopSession({
417
+ sessionId: this.session.id,
418
+ signal: opts?.signal,
419
+ blocking: opts?.blocking
420
+ })).json.session);
421
+ return this.session;
422
+ }
423
+ /**
424
+ * Update the current session's settings.
425
+ *
426
+ * @param params - Fields to update.
427
+ * @param params.networkPolicy - The new network policy to apply.
428
+ * @param opts - Optional parameters.
429
+ * @param opts.signal - An AbortSignal to cancel the operation.
430
+ *
431
+ * @example
432
+ * // Restrict to specific domains
433
+ * await session.update({
434
+ * networkPolicy: {
435
+ * allow: ["*.npmjs.org", "github.com"],
436
+ * }
437
+ * });
438
+ *
439
+ * @example
440
+ * // Inject credentials with per-domain transformers
441
+ * await session.update({
442
+ * networkPolicy: {
443
+ * allow: {
444
+ * "ai-gateway.vercel.sh": [{
445
+ * transform: [{
446
+ * headers: { authorization: "Bearer ..." }
447
+ * }]
448
+ * }],
449
+ * "*": []
450
+ * }
451
+ * }
452
+ * });
453
+ *
454
+ * @example
455
+ * // Deny all network access
456
+ * await session.update({ networkPolicy: "deny-all" });
457
+ */
458
+ async update(params, opts) {
459
+ "use step";
460
+ if (params.networkPolicy !== void 0) this.session = require_sandbox_snapshot.toSandboxSnapshot((await (await this.ensureClient()).updateNetworkPolicy({
461
+ sessionId: this.session.id,
462
+ networkPolicy: params.networkPolicy,
463
+ signal: opts?.signal
464
+ })).json.session);
465
+ }
466
+ /**
467
+ * Extend the timeout of the session by the specified duration.
468
+ *
469
+ * This allows you to extend the lifetime of a session up until the maximum
470
+ * execution timeout for your plan.
471
+ *
472
+ * @param duration - The duration in milliseconds to extend the timeout by
473
+ * @param opts - Optional parameters.
474
+ * @param opts.signal - An AbortSignal to cancel the operation.
475
+ * @returns A promise that resolves when the timeout is extended
476
+ *
477
+ * @example
478
+ * const sandbox = await Sandbox.create({ timeout: ms('10m') });
479
+ * const session = sandbox.currentSession();
480
+ * // Extends timeout by 5 minutes, to a total of 15 minutes.
481
+ * await session.extendTimeout(ms('5m'));
482
+ */
483
+ async extendTimeout(duration, opts) {
484
+ "use step";
485
+ this.session = require_sandbox_snapshot.toSandboxSnapshot((await (await this.ensureClient()).extendTimeout({
486
+ sessionId: this.session.id,
487
+ duration,
488
+ signal: opts?.signal
489
+ })).json.session);
490
+ }
491
+ /**
492
+ * Create a snapshot from this currently running session. New sandboxes can
493
+ * then be created from this snapshot using {@link Sandbox.create}.
494
+ *
495
+ * Note: this session will be stopped as part of the snapshot creation process.
496
+ *
497
+ * @param opts - Optional parameters.
498
+ * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.
499
+ * @param opts.signal - An AbortSignal to cancel the operation.
500
+ * @returns A promise that resolves to the Snapshot instance
501
+ */
502
+ async snapshot(opts) {
503
+ "use step";
504
+ const client = await this.ensureClient();
505
+ const response = await client.createSnapshot({
506
+ sessionId: this.session.id,
507
+ expiration: opts?.expiration,
508
+ signal: opts?.signal
509
+ });
510
+ this.session = require_sandbox_snapshot.toSandboxSnapshot(response.json.session);
511
+ return new require_snapshot.Snapshot({
512
+ client,
513
+ snapshot: response.json.snapshot
514
+ });
515
+ }
516
+ };
517
+
518
+ //#endregion
519
+ exports.Session = Session;
520
+ //# sourceMappingURL=session.cjs.map