disk 1.2.0 → 1.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.
package/README.md CHANGED
@@ -172,6 +172,37 @@ service-published ports. Deleting explicit exposure leaves a service publishing
172
172
  the same port reachable and does not stop the listening process. Routing changes
173
173
  may take a few seconds to propagate, and existing connections remain open.
174
174
 
175
+ `fork` pauses a running sandbox while the snapshot is taken and resumes it once the
176
+ fork is accepted. A paused or stopped sandbox is forked in place and left as it is.
177
+
178
+ For private HTTP access, create a port token without exposing the port publicly:
179
+
180
+ ```ts
181
+ const privateWeb = await client.sandboxes.create({ baseImage: "python:3.12-slim" });
182
+ const server = await privateWeb.processes.start("python -m http.server 8080 --bind 0.0.0.0");
183
+ await server.disconnect();
184
+
185
+ const access = await privateWeb.createPortToken(8080, { ttl: "1h" });
186
+ // Once the server is listening:
187
+ const response = await fetch(`https://${access.hostname}/`, {
188
+ headers: { "X-Archil-Token": access.token },
189
+ });
190
+ console.log(await response.text());
191
+
192
+ const metadata = await privateWeb.getPortToken(access.id);
193
+ const tokens = await privateWeb.listPortTokens();
194
+ const page = await privateWeb.listPortTokensPage({ limit: 10 });
195
+ await privateWeb.deletePortToken(access);
196
+ await privateWeb.delete();
197
+ ```
198
+
199
+ The secret and hostname are returned only by `createPortToken`; get/list return
200
+ metadata. Save the secret when creating it. Omit `ttl` for no expiration, or use
201
+ a duration up to `"8760h"` (365 days). `listPortTokens` follows all pages (its
202
+ `limit` caps the total); `listPortTokensPage` returns `nextCursor` for pagination.
203
+ Public ports bypass token authentication. Revocation and expiry deny new
204
+ connections with HTTP 401; existing connections remain open.
205
+
175
206
  Network egress can optionally be restricted when creating a sandbox:
176
207
 
177
208
  ```ts
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { O as ArchilApiError, a as deleteApiKey, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-Crk5lxKW.mjs";
3
- import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-DQS29KQU.mjs";
2
+ import { O as ArchilApiError, a as deleteApiKey, l as listApiKeys, n as createApiKey, r as createDisk, s as getDisk, t as configure, u as listDisks } from "./src-CvTkHglv.mjs";
3
+ import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-BFAzXgkJ.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Command } from "commander";
6
6
  //#region bin/cli.ts
@@ -1,4 +1,4 @@
1
- import { D as REGION_URLS, p as Archil } from "./src-Crk5lxKW.mjs";
1
+ import { D as REGION_URLS, p as Archil } from "./src-CvTkHglv.mjs";
2
2
  import { Option } from "commander";
3
3
  import { isCancel, password, spinner } from "@clack/prompts";
4
4
  import { chmod, mkdir, open, readFile, rename, rm, stat } from "node:fs/promises";
package/dist/index.cjs CHANGED
@@ -145,7 +145,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
145
145
  }
146
146
  //#endregion
147
147
  //#region src/version.ts
148
- const VERSION = "1.2.0";
148
+ const VERSION = "1.3.0";
149
149
  const USER_AGENT = `archil-js/${VERSION}`;
150
150
  //#endregion
151
151
  //#region src/client.ts
@@ -1853,6 +1853,14 @@ function toError(error) {
1853
1853
  }
1854
1854
  //#endregion
1855
1855
  //#region src/sandbox.ts
1856
+ function portTokenFromWire(data) {
1857
+ return {
1858
+ id: data.id,
1859
+ port: data.port,
1860
+ createdAt: new Date(data.created_at),
1861
+ expiresAt: data.expires_at ? new Date(data.expires_at) : void 0
1862
+ };
1863
+ }
1856
1864
  const POLL_INTERVAL_MS = 500;
1857
1865
  function sleep() {
1858
1866
  return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
@@ -1874,6 +1882,7 @@ var Sandbox = class Sandbox {
1874
1882
  finishedAt;
1875
1883
  lastActiveAt;
1876
1884
  exitReason;
1885
+ checkpoint;
1877
1886
  processes;
1878
1887
  files;
1879
1888
  /** @internal */
@@ -1903,6 +1912,7 @@ var Sandbox = class Sandbox {
1903
1912
  this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
1904
1913
  this.lastActiveAt = new Date(data.last_active_at);
1905
1914
  this.exitReason = data.exit_reason;
1915
+ this.checkpoint = data.checkpoint;
1906
1916
  return this;
1907
1917
  }
1908
1918
  toJSON() {
@@ -1922,7 +1932,8 @@ var Sandbox = class Sandbox {
1922
1932
  runningAt: this.runningAt,
1923
1933
  finishedAt: this.finishedAt,
1924
1934
  lastActiveAt: this.lastActiveAt,
1925
- exitReason: this.exitReason
1935
+ exitReason: this.exitReason,
1936
+ checkpoint: this.checkpoint
1926
1937
  };
1927
1938
  }
1928
1939
  /** Run a process and wait for it to exit. */
@@ -1964,17 +1975,36 @@ var Sandbox = class Sandbox {
1964
1975
  this._apply(data);
1965
1976
  return options.wait === false ? this : waitForSandboxStart(this);
1966
1977
  }
1967
- /** Create an isolated writable branch from this sandbox's current state. */
1978
+ /**
1979
+ * Create an isolated writable branch from this sandbox's current state.
1980
+ * A running sandbox is paused for the snapshot and resumed once the fork is
1981
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
1982
+ * checkpoint the pause returned, so it does not depend on the source still
1983
+ * being paused when the request lands. Resuming the source is best effort:
1984
+ * the child is returned even if the source could not be resumed, so check
1985
+ * the source's status afterwards if that matters.
1986
+ */
1968
1987
  async fork(options = {}) {
1969
- const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1988
+ const paused = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }), "transient"));
1989
+ this._apply(paused);
1990
+ const resumeAfterFork = this.status === "pausing";
1991
+ const checkpoint = this.checkpoint;
1992
+ const wait = resumeAfterFork ? false : options.wait ?? true;
1993
+ const body = {
1994
+ name: options.name,
1995
+ checkpoint
1996
+ };
1997
+ const fork = await waitWhileSandboxStatus(this, "pausing").then(() => unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1970
1998
  params: {
1971
1999
  path: { sid: this.id },
1972
- query: { wait: options.wait ?? true }
2000
+ query: { wait }
1973
2001
  },
1974
- body: options.name === void 0 ? void 0 : { name: options.name }
1975
- }), "connect"));
1976
- const fork = new Sandbox(data, this._client);
1977
- return options.wait === false ? fork : waitForSandboxStart(fork);
2002
+ body
2003
+ }), "connect"))).then((data) => new Sandbox(data, this._client)).finally(() => resumeAfterFork ? this.resume({ wait: false }).catch(() => void 0) : void 0);
2004
+ if (options.wait === false) return fork;
2005
+ await waitForSandboxStart(fork);
2006
+ if (resumeAfterFork) await waitForSandboxStart(this).catch(() => void 0);
2007
+ return fork;
1978
2008
  }
1979
2009
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
1980
2010
  async exposePort(port) {
@@ -1997,6 +2027,66 @@ var Sandbox = class Sandbox {
1997
2027
  port
1998
2028
  } } }), "transient"));
1999
2029
  }
2030
+ /** Authorize HTTP access to one port without making it public. */
2031
+ async createPortToken(port, options = {}) {
2032
+ const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/port-tokens", {
2033
+ params: { path: { sid: this.id } },
2034
+ body: {
2035
+ port,
2036
+ ttl: options.ttl
2037
+ }
2038
+ }), "connect"));
2039
+ return {
2040
+ ...portTokenFromWire(data),
2041
+ hostname: data.hostname,
2042
+ token: data.token
2043
+ };
2044
+ }
2045
+ /** Get token metadata. Expired and revoked tokens return not found. */
2046
+ async getPortToken(tokenId) {
2047
+ return portTokenFromWire(await unwrap(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2048
+ sid: this.id,
2049
+ token_id: tokenId
2050
+ } } }), "transient")));
2051
+ }
2052
+ /** List token metadata across pages. `limit` caps the total number returned. */
2053
+ async listPortTokens(options = {}) {
2054
+ const tokens = [];
2055
+ let cursor = options.cursor;
2056
+ for (;;) {
2057
+ const remaining = options.limit === void 0 ? void 0 : options.limit - tokens.length;
2058
+ if (remaining !== void 0 && remaining <= 0) return tokens;
2059
+ const page = await this.listPortTokensPage({
2060
+ limit: remaining === void 0 ? 100 : Math.min(remaining, 100),
2061
+ cursor
2062
+ });
2063
+ tokens.push(...page.tokens);
2064
+ if (!page.nextCursor) return tokens;
2065
+ cursor = page.nextCursor;
2066
+ }
2067
+ }
2068
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
2069
+ async listPortTokensPage(options = {}) {
2070
+ const { data, nextCursor } = await unwrapPage(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens", { params: {
2071
+ path: { sid: this.id },
2072
+ query: {
2073
+ limit: options.limit ?? 100,
2074
+ cursor: options.cursor
2075
+ }
2076
+ } }), "transient"));
2077
+ return {
2078
+ tokens: data.tokens.map(portTokenFromWire),
2079
+ nextCursor
2080
+ };
2081
+ }
2082
+ /** Revoke a token for new connections. Existing connections remain open. */
2083
+ async deletePortToken(token) {
2084
+ const tokenId = typeof token === "string" ? token : token.id;
2085
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2086
+ sid: this.id,
2087
+ token_id: tokenId
2088
+ } } }), "transient"));
2089
+ }
2000
2090
  /** Get this running sandbox's effective network policy. */
2001
2091
  async getNetwork() {
2002
2092
  const client = this._client;
@@ -2095,7 +2185,7 @@ var Tokens = class {
2095
2185
  return await unwrap(this._client.POST("/api/tokens", { body: req }));
2096
2186
  }
2097
2187
  async delete(id) {
2098
- await unwrapEmpty(this._client.DELETE("/api/tokens/{id}", { params: { path: { id } } }));
2188
+ await unwrapEmpty(this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }));
2099
2189
  }
2100
2190
  };
2101
2191
  //#endregion
package/dist/index.d.cts CHANGED
@@ -209,6 +209,30 @@ interface SandboxEndpoint {
209
209
  port: number;
210
210
  hostname: string;
211
211
  }
212
+ /** Port-token metadata. The secret and hostname are returned only on creation. */
213
+ interface SandboxPortToken {
214
+ id: string;
215
+ port: number;
216
+ createdAt: Date;
217
+ expiresAt?: Date;
218
+ }
219
+ interface CreatedSandboxPortToken extends SandboxPortToken {
220
+ hostname: string;
221
+ /** Send in X-Archil-Token. Save it now; it cannot be retrieved again. */
222
+ token: string;
223
+ }
224
+ interface CreateSandboxPortTokenOptions {
225
+ /** Duration such as "1h" or "30m", up to "8760h" (365 days). Omit for no expiration. */
226
+ ttl?: string;
227
+ }
228
+ interface ListSandboxPortTokensOptions {
229
+ limit?: number;
230
+ cursor?: string;
231
+ }
232
+ interface SandboxPortTokenPage {
233
+ tokens: SandboxPortToken[];
234
+ nextCursor?: string;
235
+ }
212
236
  interface SandboxResponse {
213
237
  id: string;
214
238
  name: string;
@@ -227,6 +251,8 @@ interface SandboxResponse {
227
251
  finishedAt?: Date;
228
252
  lastActiveAt: Date;
229
253
  exitReason?: string;
254
+ /** Disk checkpoint the current session leaves behind; present while pausing, paused, stopping, or stopped. */
255
+ checkpoint?: string;
230
256
  }
231
257
  interface SandboxWaitOptions {
232
258
  /**
@@ -262,6 +288,7 @@ declare class Sandbox {
262
288
  finishedAt?: Date;
263
289
  lastActiveAt: Date;
264
290
  exitReason?: string;
291
+ checkpoint?: string;
265
292
  readonly processes: SandboxProcesses;
266
293
  readonly files: SandboxFiles;
267
294
  /** @internal */
@@ -283,7 +310,15 @@ declare class Sandbox {
283
310
  pause(options?: SandboxWaitOptions): Promise<Sandbox | this>;
284
311
  /** Resume this sandbox from its preserved CPU and memory state. */
285
312
  resume(options?: SandboxWaitOptions): Promise<Sandbox | this>;
286
- /** Create an isolated writable branch from this sandbox's current state. */
313
+ /**
314
+ * Create an isolated writable branch from this sandbox's current state.
315
+ * A running sandbox is paused for the snapshot and resumed once the fork is
316
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
317
+ * checkpoint the pause returned, so it does not depend on the source still
318
+ * being paused when the request lands. Resuming the source is best effort:
319
+ * the child is returned even if the source could not be resumed, so check
320
+ * the source's status afterwards if that matters.
321
+ */
287
322
  fork(options?: SandboxForkOptions): Promise<Sandbox>;
288
323
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
289
324
  exposePort(port: number): Promise<string>;
@@ -291,6 +326,16 @@ declare class Sandbox {
291
326
  listPorts(): Promise<SandboxEndpoint[]>;
292
327
  /** Remove explicit public exposure. A service publishing the same port remains reachable. */
293
328
  unexposePort(port: number): Promise<void>;
329
+ /** Authorize HTTP access to one port without making it public. */
330
+ createPortToken(port: number, options?: CreateSandboxPortTokenOptions): Promise<CreatedSandboxPortToken>;
331
+ /** Get token metadata. Expired and revoked tokens return not found. */
332
+ getPortToken(tokenId: string): Promise<SandboxPortToken>;
333
+ /** List token metadata across pages. `limit` caps the total number returned. */
334
+ listPortTokens(options?: ListSandboxPortTokensOptions): Promise<SandboxPortToken[]>;
335
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
336
+ listPortTokensPage(options?: ListSandboxPortTokensOptions): Promise<SandboxPortTokenPage>;
337
+ /** Revoke a token for new connections. Existing connections remain open. */
338
+ deletePortToken(token: SandboxPortToken | string): Promise<void>;
294
339
  /** Get this running sandbox's effective network policy. */
295
340
  getNetwork(): Promise<SandboxNetwork>;
296
341
  /** Replace this running sandbox's complete network policy and return the effective policy. */
@@ -585,4 +630,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
585
630
  */
586
631
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
587
632
  //#endregion
588
- export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxRequest, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
633
+ export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
package/dist/index.d.mts CHANGED
@@ -209,6 +209,30 @@ interface SandboxEndpoint {
209
209
  port: number;
210
210
  hostname: string;
211
211
  }
212
+ /** Port-token metadata. The secret and hostname are returned only on creation. */
213
+ interface SandboxPortToken {
214
+ id: string;
215
+ port: number;
216
+ createdAt: Date;
217
+ expiresAt?: Date;
218
+ }
219
+ interface CreatedSandboxPortToken extends SandboxPortToken {
220
+ hostname: string;
221
+ /** Send in X-Archil-Token. Save it now; it cannot be retrieved again. */
222
+ token: string;
223
+ }
224
+ interface CreateSandboxPortTokenOptions {
225
+ /** Duration such as "1h" or "30m", up to "8760h" (365 days). Omit for no expiration. */
226
+ ttl?: string;
227
+ }
228
+ interface ListSandboxPortTokensOptions {
229
+ limit?: number;
230
+ cursor?: string;
231
+ }
232
+ interface SandboxPortTokenPage {
233
+ tokens: SandboxPortToken[];
234
+ nextCursor?: string;
235
+ }
212
236
  interface SandboxResponse {
213
237
  id: string;
214
238
  name: string;
@@ -227,6 +251,8 @@ interface SandboxResponse {
227
251
  finishedAt?: Date;
228
252
  lastActiveAt: Date;
229
253
  exitReason?: string;
254
+ /** Disk checkpoint the current session leaves behind; present while pausing, paused, stopping, or stopped. */
255
+ checkpoint?: string;
230
256
  }
231
257
  interface SandboxWaitOptions {
232
258
  /**
@@ -262,6 +288,7 @@ declare class Sandbox {
262
288
  finishedAt?: Date;
263
289
  lastActiveAt: Date;
264
290
  exitReason?: string;
291
+ checkpoint?: string;
265
292
  readonly processes: SandboxProcesses;
266
293
  readonly files: SandboxFiles;
267
294
  /** @internal */
@@ -283,7 +310,15 @@ declare class Sandbox {
283
310
  pause(options?: SandboxWaitOptions): Promise<Sandbox | this>;
284
311
  /** Resume this sandbox from its preserved CPU and memory state. */
285
312
  resume(options?: SandboxWaitOptions): Promise<Sandbox | this>;
286
- /** Create an isolated writable branch from this sandbox's current state. */
313
+ /**
314
+ * Create an isolated writable branch from this sandbox's current state.
315
+ * A running sandbox is paused for the snapshot and resumed once the fork is
316
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
317
+ * checkpoint the pause returned, so it does not depend on the source still
318
+ * being paused when the request lands. Resuming the source is best effort:
319
+ * the child is returned even if the source could not be resumed, so check
320
+ * the source's status afterwards if that matters.
321
+ */
287
322
  fork(options?: SandboxForkOptions): Promise<Sandbox>;
288
323
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
289
324
  exposePort(port: number): Promise<string>;
@@ -291,6 +326,16 @@ declare class Sandbox {
291
326
  listPorts(): Promise<SandboxEndpoint[]>;
292
327
  /** Remove explicit public exposure. A service publishing the same port remains reachable. */
293
328
  unexposePort(port: number): Promise<void>;
329
+ /** Authorize HTTP access to one port without making it public. */
330
+ createPortToken(port: number, options?: CreateSandboxPortTokenOptions): Promise<CreatedSandboxPortToken>;
331
+ /** Get token metadata. Expired and revoked tokens return not found. */
332
+ getPortToken(tokenId: string): Promise<SandboxPortToken>;
333
+ /** List token metadata across pages. `limit` caps the total number returned. */
334
+ listPortTokens(options?: ListSandboxPortTokensOptions): Promise<SandboxPortToken[]>;
335
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
336
+ listPortTokensPage(options?: ListSandboxPortTokensOptions): Promise<SandboxPortTokenPage>;
337
+ /** Revoke a token for new connections. Existing connections remain open. */
338
+ deletePortToken(token: SandboxPortToken | string): Promise<void>;
294
339
  /** Get this running sandbox's effective network policy. */
295
340
  getNetwork(): Promise<SandboxNetwork>;
296
341
  /** Replace this running sandbox's complete network policy and return the effective policy. */
@@ -585,4 +630,4 @@ declare function exec(opts: ExecOptions): Promise<ExecDiskResult>;
585
630
  */
586
631
  declare function workspace(mounts: Record<string, ExecMount>): Workspace;
587
632
  //#endregion
588
- export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxRequest, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
633
+ export { type ApiTokenResponse, type AppendObjectOptions, Archil, ArchilApiError, ArchilError, type ArchilOptions, ArchilS3Error, type AuthorizedUser, type AwsStsUser, type AzureBlobMount, type CompletedMultipartUpload, type ConnectedClient, type CreateApiTokenRequest, type CreateDiskRequest, type CreateDiskResult, type CreateSandboxPortTokenOptions, type CreateSandboxRequest, type CreatedSandboxPortToken, type Delegation, type DeleteObjectsError, type DeleteObjectsOptions, type DeleteObjectsResult, Disk, type DiskListPage, type DiskMetrics, DiskMultipart, type DiskResponse, type DiskStatus, type DiskUser, Disks, type ExecMount, type ExecMountSpec, type ExecOptions, type ExecRequest, type ExecResult, type FileSystem, type GCSMount, type GrepMatch, type GrepOptions, type GrepResult, type GrepStoppedReason, type ListDisksOptions, type ListMultipartUploadsOptions, type ListObjectsOptions, type ListObjectsResult, type ListPartsOptions, type ListSandboxPortTokensOptions, type ListSandboxesOptions, type ListTokensOptions, type MountConfig, type MountConfigResponse, type MountOptions, type MountResponse, type MultipartUpload, type MultipartUploadListing, type MultipartUploadSummary, type ObjectMetadata, type PartInfo, type PartListing, type PosixCreateAttrs, type PutObjectOptions, type PutObjectResult, type R2Mount, type RootAttrs, type S3CompatibleMount, type S3Mount, type S3Object, Sandbox, type SandboxEgressPolicy, type SandboxEgressRule, type SandboxEgressTransform, type SandboxEndpoint, type SandboxFileSource, SandboxFileTransferError, type SandboxFileUploadOptions, type SandboxFileWriter, SandboxFiles, type SandboxForkOptions, type SandboxNetwork, type SandboxNetworkAction, type SandboxPortToken, type SandboxPortTokenPage, SandboxProcess, type SandboxProcessConnectOptions, type SandboxProcessOutput, type SandboxProcessOutputHandler, type SandboxProcessResult, type SandboxProcessStartOptions, type SandboxProcessStatus, type SandboxProcessStream, SandboxProcesses, type SandboxResponse, type SandboxStatus, type SandboxTerminalOptions, type SandboxTimeoutOptions, type SandboxWaitOptions, Sandboxes, type ShareUrlOptions, type ShareUrlResult, type TokenUser, Tokens, USER_AGENT, type UploadPart, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, O as ArchilApiError, S as Disk, T as USER_AGENT, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as SandboxFileTransferError, k as ArchilError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as effectiveUploadPartSize, x as Disks, y as SandboxProcess } from "./src-Crk5lxKW.mjs";
1
+ import { A as ArchilS3Error, C as DiskMultipart, E as VERSION, O as ArchilApiError, S as Disk, T as USER_AGENT, _ as Sandbox, a as deleteApiKey, b as SandboxProcesses, c as getSandbox, d as listSandboxes, f as workspace, g as Sandboxes, h as Tokens, i as createSandbox, j as SandboxFileTransferError, k as ArchilError, l as listApiKeys, m as Workspace, n as createApiKey, o as exec, p as Archil, r as createDisk, s as getDisk, t as configure, u as listDisks, v as SandboxFiles, w as effectiveUploadPartSize, x as Disks, y as SandboxProcess } from "./src-CvTkHglv.mjs";
2
2
  export { Archil, ArchilApiError, ArchilError, ArchilS3Error, Disk, DiskMultipart, Disks, Sandbox, SandboxFileTransferError, SandboxFiles, SandboxProcess, SandboxProcesses, Sandboxes, Tokens, USER_AGENT, VERSION, Workspace, configure, createApiKey, createDisk, createSandbox, deleteApiKey, effectiveUploadPartSize, exec, getDisk, getSandbox, listApiKeys, listDisks, listSandboxes, workspace };
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { O as ArchilApiError, p as Archil } from "./src-Crk5lxKW.mjs";
3
- import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-DQS29KQU.mjs";
2
+ import { O as ArchilApiError, p as Archil } from "./src-CvTkHglv.mjs";
3
+ import { a as renderTable, i as resolveProgramCredentials, n as addProfileCommands, r as isProfileCommand, t as addGlobalOptions } from "./common-BFAzXgkJ.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { Command } from "commander";
6
6
  import { spinner } from "@clack/prompts";
@@ -122,7 +122,7 @@ function deriveS3BaseUrl(controlBaseUrl) {
122
122
  }
123
123
  //#endregion
124
124
  //#region src/version.ts
125
- const VERSION = "1.2.0";
125
+ const VERSION = "1.3.0";
126
126
  const USER_AGENT = `archil-js/${VERSION}`;
127
127
  //#endregion
128
128
  //#region src/client.ts
@@ -1830,6 +1830,14 @@ function toError(error) {
1830
1830
  }
1831
1831
  //#endregion
1832
1832
  //#region src/sandbox.ts
1833
+ function portTokenFromWire(data) {
1834
+ return {
1835
+ id: data.id,
1836
+ port: data.port,
1837
+ createdAt: new Date(data.created_at),
1838
+ expiresAt: data.expires_at ? new Date(data.expires_at) : void 0
1839
+ };
1840
+ }
1833
1841
  const POLL_INTERVAL_MS = 500;
1834
1842
  function sleep() {
1835
1843
  return new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
@@ -1851,6 +1859,7 @@ var Sandbox = class Sandbox {
1851
1859
  finishedAt;
1852
1860
  lastActiveAt;
1853
1861
  exitReason;
1862
+ checkpoint;
1854
1863
  processes;
1855
1864
  files;
1856
1865
  /** @internal */
@@ -1880,6 +1889,7 @@ var Sandbox = class Sandbox {
1880
1889
  this.finishedAt = data.finished_at ? new Date(data.finished_at) : void 0;
1881
1890
  this.lastActiveAt = new Date(data.last_active_at);
1882
1891
  this.exitReason = data.exit_reason;
1892
+ this.checkpoint = data.checkpoint;
1883
1893
  return this;
1884
1894
  }
1885
1895
  toJSON() {
@@ -1899,7 +1909,8 @@ var Sandbox = class Sandbox {
1899
1909
  runningAt: this.runningAt,
1900
1910
  finishedAt: this.finishedAt,
1901
1911
  lastActiveAt: this.lastActiveAt,
1902
- exitReason: this.exitReason
1912
+ exitReason: this.exitReason,
1913
+ checkpoint: this.checkpoint
1903
1914
  };
1904
1915
  }
1905
1916
  /** Run a process and wait for it to exit. */
@@ -1941,17 +1952,36 @@ var Sandbox = class Sandbox {
1941
1952
  this._apply(data);
1942
1953
  return options.wait === false ? this : waitForSandboxStart(this);
1943
1954
  }
1944
- /** Create an isolated writable branch from this sandbox's current state. */
1955
+ /**
1956
+ * Create an isolated writable branch from this sandbox's current state.
1957
+ * A running sandbox is paused for the snapshot and resumed once the fork is
1958
+ * accepted; a paused or stopped sandbox is left as it is. The fork names the
1959
+ * checkpoint the pause returned, so it does not depend on the source still
1960
+ * being paused when the request lands. Resuming the source is best effort:
1961
+ * the child is returned even if the source could not be resumed, so check
1962
+ * the source's status afterwards if that matters.
1963
+ */
1945
1964
  async fork(options = {}) {
1946
- const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1965
+ const paused = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/pause", { params: { path: { sid: this.id } } }), "transient"));
1966
+ this._apply(paused);
1967
+ const resumeAfterFork = this.status === "pausing";
1968
+ const checkpoint = this.checkpoint;
1969
+ const wait = resumeAfterFork ? false : options.wait ?? true;
1970
+ const body = {
1971
+ name: options.name,
1972
+ checkpoint
1973
+ };
1974
+ const fork = await waitWhileSandboxStatus(this, "pausing").then(() => unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/fork", {
1947
1975
  params: {
1948
1976
  path: { sid: this.id },
1949
- query: { wait: options.wait ?? true }
1977
+ query: { wait }
1950
1978
  },
1951
- body: options.name === void 0 ? void 0 : { name: options.name }
1952
- }), "connect"));
1953
- const fork = new Sandbox(data, this._client);
1954
- return options.wait === false ? fork : waitForSandboxStart(fork);
1979
+ body
1980
+ }), "connect"))).then((data) => new Sandbox(data, this._client)).finally(() => resumeAfterFork ? this.resume({ wait: false }).catch(() => void 0) : void 0);
1981
+ if (options.wait === false) return fork;
1982
+ await waitForSandboxStart(fork);
1983
+ if (resumeAfterFork) await waitForSandboxStart(this).catch(() => void 0);
1984
+ return fork;
1955
1985
  }
1956
1986
  /** Expose a TCP port publicly (1–65535), returning its hostname. */
1957
1987
  async exposePort(port) {
@@ -1974,6 +2004,66 @@ var Sandbox = class Sandbox {
1974
2004
  port
1975
2005
  } } }), "transient"));
1976
2006
  }
2007
+ /** Authorize HTTP access to one port without making it public. */
2008
+ async createPortToken(port, options = {}) {
2009
+ const data = await unwrap(retryApiRequest(() => this._client.POST("/api/sandboxes/{sid}/port-tokens", {
2010
+ params: { path: { sid: this.id } },
2011
+ body: {
2012
+ port,
2013
+ ttl: options.ttl
2014
+ }
2015
+ }), "connect"));
2016
+ return {
2017
+ ...portTokenFromWire(data),
2018
+ hostname: data.hostname,
2019
+ token: data.token
2020
+ };
2021
+ }
2022
+ /** Get token metadata. Expired and revoked tokens return not found. */
2023
+ async getPortToken(tokenId) {
2024
+ return portTokenFromWire(await unwrap(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2025
+ sid: this.id,
2026
+ token_id: tokenId
2027
+ } } }), "transient")));
2028
+ }
2029
+ /** List token metadata across pages. `limit` caps the total number returned. */
2030
+ async listPortTokens(options = {}) {
2031
+ const tokens = [];
2032
+ let cursor = options.cursor;
2033
+ for (;;) {
2034
+ const remaining = options.limit === void 0 ? void 0 : options.limit - tokens.length;
2035
+ if (remaining !== void 0 && remaining <= 0) return tokens;
2036
+ const page = await this.listPortTokensPage({
2037
+ limit: remaining === void 0 ? 100 : Math.min(remaining, 100),
2038
+ cursor
2039
+ });
2040
+ tokens.push(...page.tokens);
2041
+ if (!page.nextCursor) return tokens;
2042
+ cursor = page.nextCursor;
2043
+ }
2044
+ }
2045
+ /** Fetch one page of token metadata; pass `nextCursor` back as `cursor`. */
2046
+ async listPortTokensPage(options = {}) {
2047
+ const { data, nextCursor } = await unwrapPage(retryApiRequest(() => this._client.GET("/api/sandboxes/{sid}/port-tokens", { params: {
2048
+ path: { sid: this.id },
2049
+ query: {
2050
+ limit: options.limit ?? 100,
2051
+ cursor: options.cursor
2052
+ }
2053
+ } }), "transient"));
2054
+ return {
2055
+ tokens: data.tokens.map(portTokenFromWire),
2056
+ nextCursor
2057
+ };
2058
+ }
2059
+ /** Revoke a token for new connections. Existing connections remain open. */
2060
+ async deletePortToken(token) {
2061
+ const tokenId = typeof token === "string" ? token : token.id;
2062
+ await unwrapEmpty(retryApiRequest(() => this._client.DELETE("/api/sandboxes/{sid}/port-tokens/{token_id}", { params: { path: {
2063
+ sid: this.id,
2064
+ token_id: tokenId
2065
+ } } }), "transient"));
2066
+ }
1977
2067
  /** Get this running sandbox's effective network policy. */
1978
2068
  async getNetwork() {
1979
2069
  const client = this._client;
@@ -2072,7 +2162,7 @@ var Tokens = class {
2072
2162
  return await unwrap(this._client.POST("/api/tokens", { body: req }));
2073
2163
  }
2074
2164
  async delete(id) {
2075
- await unwrapEmpty(this._client.DELETE("/api/tokens/{id}", { params: { path: { id } } }));
2165
+ await unwrapEmpty(this._client.DELETE("/api/tokens/{tokenId}", { params: { path: { tokenId: id } } }));
2076
2166
  }
2077
2167
  };
2078
2168
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "disk",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Pure-JS client and CLIs for Archil disks and sandboxes",
5
5
  "keywords": [
6
6
  "archil",
@@ -40,7 +40,7 @@
40
40
  "LICENSE"
41
41
  ],
42
42
  "dependencies": {
43
- "@archildata/api-types": "^0.0.24",
43
+ "@archildata/api-types": "^0.0.40",
44
44
  "@clack/prompts": "^1.7.0",
45
45
  "commander": "^14.0.3",
46
46
  "fast-xml-parser": "^5.7.0",