withruntime 0.8.4 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/BLAXEL.md +4 -4
  2. package/COMPATIBILITY.md +145 -0
  3. package/DAYTONA.md +13 -7
  4. package/E2B.md +34 -20
  5. package/README.md +22 -11
  6. package/README.src.md +22 -11
  7. package/VERCEL.md +13 -3
  8. package/compatibility-lock.json +357 -0
  9. package/dist/ai-harness/index.js +2 -2
  10. package/dist/api-defaults.d.ts +17 -0
  11. package/dist/api-defaults.js +22 -0
  12. package/dist/blaxel/errors.js +1 -1
  13. package/dist/blaxel/lookup.d.ts +3 -2
  14. package/dist/blaxel/lookup.js +3 -2
  15. package/dist/blaxel/pagination.d.ts +2 -2
  16. package/dist/blaxel/pagination.js +45 -17
  17. package/dist/blaxel/preview.d.ts +3 -2
  18. package/dist/blaxel/preview.js +16 -14
  19. package/dist/blaxel/process.d.ts +1 -1
  20. package/dist/blaxel/process.js +66 -11
  21. package/dist/blaxel/sandbox.d.ts +2 -0
  22. package/dist/blaxel/sandbox.js +2 -0
  23. package/dist/blaxel/snapshot.js +3 -5
  24. package/dist/cli-words.d.ts +27 -0
  25. package/dist/cli-words.js +135 -0
  26. package/dist/cli.d.ts +2 -0
  27. package/dist/cli.js +351 -85
  28. package/dist/client.d.ts +33 -4
  29. package/dist/client.js +47 -12
  30. package/dist/cloudflare/identity.d.ts +7 -0
  31. package/dist/cloudflare/identity.js +13 -0
  32. package/dist/cloudflare/index.d.ts +303 -0
  33. package/dist/cloudflare/index.js +592 -0
  34. package/dist/cloudflare/worker.d.ts +419 -0
  35. package/dist/cloudflare/worker.js +447 -0
  36. package/dist/codesandbox/guest-service.d.ts +31 -0
  37. package/dist/codesandbox/guest-service.js +490 -0
  38. package/dist/codesandbox/index.d.ts +386 -0
  39. package/dist/codesandbox/index.js +1347 -0
  40. package/dist/compat/core.d.ts +40 -0
  41. package/dist/compat/core.js +238 -0
  42. package/dist/compat/files.d.ts +26 -0
  43. package/dist/compat/files.js +133 -0
  44. package/dist/compat/shell.d.ts +4 -0
  45. package/dist/compat/shell.js +165 -0
  46. package/dist/credentials.d.ts +6 -1
  47. package/dist/credentials.js +107 -38
  48. package/dist/daytona/context.js +2 -1
  49. package/dist/daytona/daytona.js +11 -4
  50. package/dist/daytona/filesystem.d.ts +17 -4
  51. package/dist/daytona/filesystem.js +121 -38
  52. package/dist/daytona/index.d.ts +1 -1
  53. package/dist/daytona/process.d.ts +1 -1
  54. package/dist/daytona/process.js +27 -4
  55. package/dist/daytona/sandbox.d.ts +1 -1
  56. package/dist/daytona/sandbox.js +16 -7
  57. package/dist/e2b/client.js +1 -1
  58. package/dist/e2b/code-interpreter.d.ts +4 -5
  59. package/dist/e2b/code-interpreter.js +54 -56
  60. package/dist/e2b/commands.d.ts +35 -12
  61. package/dist/e2b/commands.js +169 -73
  62. package/dist/e2b/errors.js +1 -1
  63. package/dist/e2b/filesystem.d.ts +8 -6
  64. package/dist/e2b/filesystem.js +127 -28
  65. package/dist/e2b/index.d.ts +1 -0
  66. package/dist/e2b/index.js +1 -0
  67. package/dist/e2b/pty.d.ts +24 -0
  68. package/dist/e2b/pty.js +80 -0
  69. package/dist/e2b/sandbox.d.ts +6 -4
  70. package/dist/e2b/sandbox.js +59 -25
  71. package/dist/errors.d.ts +8 -0
  72. package/dist/errors.js +15 -2
  73. package/dist/file-source.d.ts +16 -0
  74. package/dist/file-source.js +162 -0
  75. package/dist/freestyle/index.d.ts +309 -0
  76. package/dist/freestyle/index.js +343 -0
  77. package/dist/index.d.ts +3 -1
  78. package/dist/login.js +16 -10
  79. package/dist/mcp.js +2 -2
  80. package/dist/modal/index.d.ts +205 -0
  81. package/dist/modal/index.js +486 -0
  82. package/dist/network-cli.js +112 -44
  83. package/dist/openai-agents/index.js +18 -71
  84. package/dist/page.d.ts +1 -1
  85. package/dist/page.js +2 -2
  86. package/dist/products/audit.d.ts +3 -0
  87. package/dist/products/index.d.ts +14 -0
  88. package/dist/products/index.js +12 -0
  89. package/dist/products/interpreter.d.ts +11 -4
  90. package/dist/products/interpreter.js +33 -9
  91. package/dist/products/jobs.js +3 -2
  92. package/dist/products/limits.d.ts +10 -0
  93. package/dist/products/observability.d.ts +44 -0
  94. package/dist/products/observability.js +6 -0
  95. package/dist/products/previews.d.ts +18 -4
  96. package/dist/products/previews.js +14 -5
  97. package/dist/products/tailscale.d.ts +57 -0
  98. package/dist/products/tailscale.js +17 -0
  99. package/dist/products/volumes.d.ts +42 -0
  100. package/dist/products/volumes.js +36 -0
  101. package/dist/products/watch.d.ts +25 -4
  102. package/dist/products/watch.js +132 -18
  103. package/dist/proxy.js +3 -1
  104. package/dist/runloop/index.d.ts +326 -0
  105. package/dist/runloop/index.js +535 -0
  106. package/dist/runloop/pagination.d.ts +46 -0
  107. package/dist/runloop/pagination.js +82 -0
  108. package/dist/runloop/snapshots.d.ts +52 -0
  109. package/dist/runloop/snapshots.js +244 -0
  110. package/dist/sandbox.d.ts +76 -16
  111. package/dist/sandbox.js +696 -135
  112. package/dist/snapshots.d.ts +20 -5
  113. package/dist/snapshots.js +11 -1
  114. package/dist/sprites/index.d.ts +251 -0
  115. package/dist/sprites/index.js +588 -0
  116. package/dist/tar.d.ts +10 -1
  117. package/dist/tar.js +311 -35
  118. package/dist/tools/index.js +2 -1
  119. package/dist/transport.d.ts +23 -8
  120. package/dist/transport.js +247 -127
  121. package/dist/types.d.ts +52 -3
  122. package/dist/vercel/command.d.ts +1 -1
  123. package/dist/vercel/command.js +15 -3
  124. package/dist/vercel/errors.d.ts +2 -2
  125. package/dist/vercel/errors.js +19 -2
  126. package/dist/vercel/filesystem.d.ts +21 -18
  127. package/dist/vercel/filesystem.js +95 -48
  128. package/dist/vercel/sandbox.d.ts +8 -8
  129. package/dist/vercel/sandbox.js +159 -64
  130. package/dist/vercel/snapshot.d.ts +3 -2
  131. package/dist/vercel/snapshot.js +9 -5
  132. package/package.json +46 -3
package/dist/client.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  import { RuntimeError } from "./errors.js";
2
2
  import type { Page } from "./page.js";
3
3
  import { type ClientExtensions } from "./products/index.js";
4
+ import { usageExport as makeUsageExport } from "./products/observability.js";
4
5
  import { Sandbox } from "./sandbox.js";
5
6
  import { Snapshots } from "./snapshots.js";
6
7
  import { Transport, type RequestOptions } from "./transport.js";
7
- import type { CreateSandbox, FeedbackKind, SandboxInfo, Usage } from "./types.js";
8
+ import type { CreateSandbox, DeletedSandbox, FeedbackKind, SandboxInfo, Usage } from "./types.js";
8
9
  export type RuntimeOptions = {
9
10
  /** Default: the RUNTIME_API_KEY environment variable. */
10
11
  apiKey?: string;
11
12
  /** Default: RUNTIME_API_URL, then https://api.withruntime.com. */
12
13
  baseUrl?: string;
13
14
  fetch?: typeof fetch;
14
- /** Per call, retries included. Default 5 minutes. */
15
+ /** Per call, queue and retries included. Default 5 minutes; 0 disables it. */
15
16
  timeoutMs?: number;
16
17
  /** Retries of transport failures, 429, 502, 503 and 504. Default 4. */
17
18
  maxRetries?: number;
@@ -30,11 +31,16 @@ export interface Runtime extends ClientExtensions {
30
31
  }
31
32
  export declare class Runtime {
32
33
  readonly transport: Transport;
34
+ /** The sandbox product; `sandboxes` remains the same client for compatibility. */
35
+ readonly sandbox: Sandboxes;
33
36
  readonly sandboxes: Sandboxes;
37
+ readonly snapshot: Snapshots;
34
38
  readonly snapshots: Snapshots;
35
39
  readonly feedback: FeedbackApi;
36
40
  readonly support: SupportApi;
37
41
  readonly account: AccountApi;
42
+ /** Date-range settlements, paged with exact charges and the server's CSV. */
43
+ readonly usageExport: ReturnType<typeof makeUsageExport>;
38
44
  constructor(options?: RuntimeOptions);
39
45
  /** Who this key is: organization, agent and credential. */
40
46
  me(options?: RequestOptions): Promise<{
@@ -50,6 +56,25 @@ export declare class Runtime {
50
56
  /** Balance, holds, trial time and per-resource charges, in integer microdollars. */
51
57
  /** Credit, holds, trial time and per-resource charges. */
52
58
  usage(options?: RequestOptions): Promise<Usage>;
59
+ /** This account's authenticated API answers, in hourly windows. Counts are
60
+ * exact decimal strings, and an empty window has a null error percentage.
61
+ * A key needs usage permission. */
62
+ usageRequests(range?: "24h" | "7d" | "30d" | "90d", options?: RequestOptions): Promise<{
63
+ range: "24h" | "7d" | "30d" | "90d";
64
+ since: string;
65
+ until: string;
66
+ calls: string;
67
+ clientErrors: string;
68
+ serverErrors: string;
69
+ errorPercent: number | null;
70
+ operations: Array<{
71
+ operation: string;
72
+ calls: string;
73
+ clientErrors: string;
74
+ serverErrors: string;
75
+ errorPercent: number | null;
76
+ }>;
77
+ }>;
53
78
  }
54
79
  /** How `sandboxes.create` waits when every trial slot, the account's quota or
55
80
  * the region is full. */
@@ -80,7 +105,11 @@ export declare class Sandboxes {
80
105
  wait?: boolean;
81
106
  }, options?: CreateOptions): Promise<Sandbox>;
82
107
  get(id: string, options?: RequestOptions): Promise<Sandbox>;
83
- /** Live sandboxes, oldest first. Await for a page, or `for await` over all. */
108
+ /** Deletes a sandbox for good, by id, without reading it first: see
109
+ * `sandbox.delete()`. Deleting it again answers the same. */
110
+ delete(id: string, options?: RequestOptions): Promise<DeletedSandbox>;
111
+ /** Live sandboxes, oldest first. Await for a page, or `for await` over all.
112
+ * Request options apply to the initial request and every subsequent page. */
84
113
  list(filter?: {
85
114
  state?: SandboxInfo["state"][];
86
115
  includeStopped?: boolean;
@@ -88,7 +117,7 @@ export declare class Sandboxes {
88
117
  labels?: Record<string, string>;
89
118
  name?: string;
90
119
  limit?: number;
91
- }): Promise<Page<Sandbox>>;
120
+ }, options?: RequestOptions): Promise<Page<Sandbox>>;
92
121
  }
93
122
  export declare class FeedbackApi {
94
123
  private readonly t;
package/dist/client.js CHANGED
@@ -1,14 +1,17 @@
1
+ import { WAIT_FOR_TIMEOUT_SECONDS } from "./api-defaults.js";
1
2
  import { RuntimeError } from "./errors.js";
2
- import { clientFactories } from "./products/index.js";
3
- import { Sandbox, sandboxPage } from "./sandbox.js";
3
+ import { clientFactories, clientProductAliases } from "./products/index.js";
4
+ import { usageExport as makeUsageExport } from "./products/observability.js";
5
+ import { Sandbox, deleteSandbox, sandboxPage } from "./sandbox.js";
4
6
  import { Snapshots } from "./snapshots.js";
5
7
  import { Transport, missingKey } from "./transport.js";
6
- /** The key `runtime login` saved for this machine, found on first use. */
7
- const savedKey = async () => {
8
+ /** The key `runtime login` saved for this machine and this API origin, found
9
+ * on first use. A constructor override must never receive another API's key. */
10
+ const savedKey = async (apiOrigin) => {
8
11
  if (typeof process === "undefined" || !process.versions?.node)
9
12
  throw missingKey();
10
13
  const { resolveCredential } = await import("./credentials.js");
11
- return resolveCredential(process.env);
14
+ return resolveCredential({ ...process.env, RUNTIME_API_URL: apiOrigin });
12
15
  };
13
16
  const env = (name) => typeof process === "undefined"
14
17
  ? undefined
@@ -16,32 +19,42 @@ const env = (name) => typeof process === "undefined"
16
19
  // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
17
20
  export class Runtime {
18
21
  transport;
22
+ /** The sandbox product; `sandboxes` remains the same client for compatibility. */
23
+ sandbox;
19
24
  sandboxes;
25
+ snapshot;
20
26
  snapshots;
21
27
  feedback;
22
28
  support;
23
29
  account;
30
+ /** Date-range settlements, paged with exact charges and the server's CSV. */
31
+ usageExport;
24
32
  constructor(options = {}) {
25
33
  this.transport = new Transport({
26
34
  // A key given, then RUNTIME_API_KEY, then (in Node and Bun) the key
27
35
  // `runtime login` saved for this machine, read on the first call.
28
- apiKey: options.apiKey ?? env("RUNTIME_API_KEY") ?? savedKey,
36
+ apiKey: options.apiKey ?? env("RUNTIME_API_KEY") ?? (() => savedKey(this.transport.baseUrl)),
29
37
  baseUrl: options.baseUrl ?? env("RUNTIME_API_URL"),
30
38
  ...(options.fetch ? { fetch: options.fetch } : {}),
31
- ...(options.timeoutMs ? { timeoutMs: options.timeoutMs } : {}),
39
+ ...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
32
40
  ...(options.maxRetries !== undefined ? { maxRetries: options.maxRetries } : {}),
33
- ...(options.maxConnections ? { maxConnections: options.maxConnections } : {}),
41
+ ...(options.maxConnections !== undefined ? { maxConnections: options.maxConnections } : {}),
34
42
  ...(options.waitForCapacityMs !== undefined
35
43
  ? { waitForCapacityMs: options.waitForCapacityMs }
36
44
  : {}),
37
45
  });
38
46
  this.sandboxes = new Sandboxes(this.transport);
47
+ this.sandbox = this.sandboxes;
39
48
  this.snapshots = new Snapshots(this.transport);
49
+ this.snapshot = this.snapshots;
40
50
  this.feedback = new FeedbackApi(this.transport);
41
51
  this.support = new SupportApi(this.transport);
42
52
  this.account = new AccountApi(this.transport);
53
+ this.usageExport = makeUsageExport(this.transport);
43
54
  for (const [name, make] of clientFactories())
44
55
  Object.defineProperty(this, name, { value: make(this.transport), enumerable: true });
56
+ for (const [alias, name] of Object.entries(clientProductAliases))
57
+ Object.defineProperty(this, alias, { value: this[name], enumerable: true });
45
58
  }
46
59
  /** Who this key is: organization, agent and credential. */
47
60
  me(options = {}) {
@@ -60,6 +73,17 @@ export class Runtime {
60
73
  ...options,
61
74
  });
62
75
  }
76
+ /** This account's authenticated API answers, in hourly windows. Counts are
77
+ * exact decimal strings, and an empty window has a null error percentage.
78
+ * A key needs usage permission. */
79
+ usageRequests(range = "24h", options = {}) {
80
+ return this.transport.json({
81
+ method: "GET",
82
+ path: "/v1/usage/requests",
83
+ query: { range },
84
+ ...options,
85
+ });
86
+ }
63
87
  }
64
88
  export class Sandboxes {
65
89
  t;
@@ -83,7 +107,12 @@ export class Sandboxes {
83
107
  });
84
108
  const sandbox = new Sandbox(this.t, info);
85
109
  if (wait !== false && info.state !== "running") {
86
- await sandbox.waitFor("running", { timeoutSeconds: 60 });
110
+ await sandbox.waitFor("running", {
111
+ timeoutSeconds: WAIT_FOR_TIMEOUT_SECONDS,
112
+ signal: options.signal,
113
+ timeoutMs: options.timeoutMs,
114
+ idempotencyKey: options.idempotencyKey,
115
+ });
87
116
  if (sandbox.state !== "running")
88
117
  throw new RuntimeError({
89
118
  message: `Sandbox ${info.id} is ${sandbox.state}, not running.`,
@@ -108,8 +137,14 @@ export class Sandboxes {
108
137
  ...options,
109
138
  }));
110
139
  }
111
- /** Live sandboxes, oldest first. Await for a page, or `for await` over all. */
112
- async list(filter = {}) {
140
+ /** Deletes a sandbox for good, by id, without reading it first: see
141
+ * `sandbox.delete()`. Deleting it again answers the same. */
142
+ delete(id, options = {}) {
143
+ return deleteSandbox(this.t, id, options);
144
+ }
145
+ /** Live sandboxes, oldest first. Await for a page, or `for await` over all.
146
+ * Request options apply to the initial request and every subsequent page. */
147
+ async list(filter = {}, options = {}) {
113
148
  const query = {
114
149
  ...(filter.state ? { state: filter.state } : {}),
115
150
  ...(filter.includeStopped ? { includeStopped: true } : {}),
@@ -119,7 +154,7 @@ export class Sandboxes {
119
154
  ...(filter.name ? { name: filter.name } : {}),
120
155
  ...(filter.limit ? { limit: filter.limit } : {}),
121
156
  };
122
- return sandboxPage(this.t, await this.t.json({ method: "GET", path: "/v1/sandboxes", query }), query);
157
+ return sandboxPage(this.t, await this.t.json({ method: "GET", path: "/v1/sandboxes", query, ...options }), query, options);
123
158
  }
124
159
  }
125
160
  export class FeedbackApi {
@@ -0,0 +1,7 @@
1
+ /** A Durable Object ID includes its namespace; a display name does not. */
2
+ export declare function workerSandboxIdentity(objectId: string, stored: {
3
+ nativeSandboxId?: string;
4
+ sandboxName?: {
5
+ name: string;
6
+ };
7
+ }): string;
@@ -0,0 +1,13 @@
1
+ /** A Durable Object ID includes its namespace; a display name does not. */
2
+ export function workerSandboxIdentity(objectId, stored) {
3
+ if (stored.nativeSandboxId !== undefined) {
4
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/.test(stored.nativeSandboxId))
5
+ throw new Error("The stored Runtime sandbox identity is invalid");
6
+ return stored.nativeSandboxId;
7
+ }
8
+ if (stored.sandboxName)
9
+ throw new Error("This legacy Durable Object has no namespace-safe Runtime identity. Retain its existing sandbox and migrate its identity explicitly before using it.");
10
+ if (!/^[a-f0-9]{64}$/.test(objectId))
11
+ throw new Error("The Durable Object identity is invalid");
12
+ return `cf-do-${objectId}`;
13
+ }
@@ -0,0 +1,303 @@
1
+ import { Runtime } from "../client.js";
2
+ import type { Process as NativeProcess, Sandbox as NativeSandbox } from "../sandbox.js";
3
+ import { CompatibilityError, type ClientOptions } from "../compat/core.js";
4
+ export { CompatibilityError };
5
+ export declare class SandboxSecurityError extends Error {
6
+ readonly code: string;
7
+ constructor(message: string, code: string);
8
+ }
9
+ export declare function sanitizeSandboxId(id: string): string;
10
+ export interface SandboxOptions {
11
+ sleepAfter?: string | number;
12
+ keepAlive?: boolean;
13
+ normalizeId?: boolean;
14
+ runtime?: ClientOptions;
15
+ }
16
+ export interface ExecOptions {
17
+ timeout?: number;
18
+ env?: Record<string, string | undefined>;
19
+ cwd?: string;
20
+ encoding?: string;
21
+ stream?: boolean;
22
+ onOutput?: (stream: "stdout" | "stderr", data: string) => void;
23
+ onComplete?: (result: ExecResult) => void;
24
+ onError?: (error: Error) => void;
25
+ signal?: AbortSignal;
26
+ }
27
+ export interface ExecResult {
28
+ success: boolean;
29
+ exitCode: number;
30
+ stdout: string;
31
+ stderr: string;
32
+ command: string;
33
+ duration: number;
34
+ timestamp: string;
35
+ sessionId?: string;
36
+ }
37
+ export interface ReadFileResult {
38
+ success: boolean;
39
+ path: string;
40
+ content: string;
41
+ encoding: "utf-8" | "base64";
42
+ isBinary: boolean;
43
+ size: number;
44
+ timestamp: string;
45
+ }
46
+ export interface ReadFileStreamResult {
47
+ success: true;
48
+ path: string;
49
+ content: ReadableStream<Uint8Array>;
50
+ size: number;
51
+ mimeType: string;
52
+ timestamp: string;
53
+ }
54
+ export interface SessionOptions {
55
+ id?: string;
56
+ name?: string;
57
+ env?: Record<string, string | undefined>;
58
+ cwd?: string;
59
+ isolation?: boolean;
60
+ commandTimeoutMs?: number;
61
+ }
62
+ export interface ProcessOptions {
63
+ timeout?: number;
64
+ env?: Record<string, string | undefined>;
65
+ cwd?: string;
66
+ encoding?: string;
67
+ sessionId?: string;
68
+ onOutput?: (stream: "stdout" | "stderr", data: string) => void;
69
+ onExit?: (code: number | null) => void;
70
+ onStart?: (process: Process) => void;
71
+ onError?: (error: Error) => void;
72
+ }
73
+ export declare function validateSandboxConfiguration(options: Pick<SandboxOptions, "sleepAfter" | "keepAlive">): void;
74
+ /** Worker bindings are deliberately not inspected or invoked. Supply Runtime credentials
75
+ * through options.runtime in Workers; Node also supports RUNTIME_API_KEY/login. */
76
+ export declare function getSandbox(namespace: unknown, id: string, options?: SandboxOptions): Sandbox;
77
+ export declare class Sandbox {
78
+ readonly runtime: Runtime;
79
+ private readonly options;
80
+ private pending?;
81
+ private existing?;
82
+ readonly id: string;
83
+ constructor(runtime: Runtime, id: string, options?: SandboxOptions);
84
+ configure(options: Pick<SandboxOptions, "sleepAfter" | "keepAlive">): Promise<void>;
85
+ /** Only a successfully initialized native handle can supply a recovery id. */
86
+ existingNativeId(): string | undefined;
87
+ /** Reconcile an uncertain update from an authoritative read, without allocation. */
88
+ reconcileConfiguration(nativeId?: string | undefined): Promise<{
89
+ sleepAfter: number;
90
+ keepAlive: boolean;
91
+ }>;
92
+ native(): Promise<NativeSandbox>;
93
+ private session;
94
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
95
+ execStream(command: string, options?: ExecOptions): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
96
+ startProcess(command: string, options?: ProcessOptions): Promise<Process>;
97
+ createSession(options?: SessionOptions): Promise<ExecutionSession>;
98
+ getSession(id: string): Promise<ExecutionSession>;
99
+ deleteSession(id: string): Promise<{
100
+ success: boolean;
101
+ sessionId: string;
102
+ timestamp: string;
103
+ }>;
104
+ destroy(): Promise<void>;
105
+ setEnvVars(env: Record<string, string | undefined>): Promise<void>;
106
+ writeFile(path: string, content: string | ReadableStream<Uint8Array>, options?: {
107
+ encoding?: string;
108
+ }): Promise<{
109
+ success: boolean;
110
+ path: string;
111
+ bytesWritten: number;
112
+ timestamp: string;
113
+ }>;
114
+ readFile(path: string, options: {
115
+ encoding: "none";
116
+ }): Promise<ReadFileStreamResult>;
117
+ readFile(path: string, options?: {
118
+ encoding?: "utf8" | "utf-8" | "base64";
119
+ }): Promise<ReadFileResult>;
120
+ mkdir(path: string, options?: {
121
+ recursive?: boolean;
122
+ }): Promise<{
123
+ success: boolean;
124
+ path: string;
125
+ timestamp: string;
126
+ }>;
127
+ deleteFile(path: string): Promise<{
128
+ success: boolean;
129
+ path: string;
130
+ timestamp: string;
131
+ }>;
132
+ renameFile(from: string, to: string): Promise<{
133
+ success: boolean;
134
+ path: string;
135
+ newPath: string;
136
+ timestamp: string;
137
+ }>;
138
+ moveFile(from: string, to: string): Promise<{
139
+ success: boolean;
140
+ path: string;
141
+ newPath: string;
142
+ timestamp: string;
143
+ }>;
144
+ listFiles(path: string, options?: {
145
+ recursive?: boolean;
146
+ includeHidden?: boolean;
147
+ }): Promise<{
148
+ success: boolean;
149
+ path: string;
150
+ files: {
151
+ absolutePath: string;
152
+ relativePath: string;
153
+ permissions: {
154
+ readable: boolean;
155
+ writable: boolean;
156
+ executable: boolean;
157
+ };
158
+ name: string;
159
+ path: string;
160
+ type: "file" | "directory" | "symlink" | "other";
161
+ size: number;
162
+ mode: string;
163
+ modifiedAt: string;
164
+ uid?: number;
165
+ gid?: number;
166
+ owner?: string;
167
+ group?: string;
168
+ symlinkTarget?: string;
169
+ }[];
170
+ count: number;
171
+ timestamp: string;
172
+ }>;
173
+ exists(path: string): Promise<{
174
+ success: boolean;
175
+ path: string;
176
+ exists: boolean;
177
+ timestamp: string;
178
+ }>;
179
+ listProcesses(): Promise<Process[]>;
180
+ getProcess(id: string): Promise<Process | null>;
181
+ killProcess(id: string, signal?: string): Promise<void>;
182
+ killAllProcesses(): Promise<number>;
183
+ getProcessLogs(id: string): Promise<{
184
+ stdout: string;
185
+ stderr: string;
186
+ processId: string;
187
+ }>;
188
+ exposePort(port: number, options: {
189
+ name?: string;
190
+ hostname: string;
191
+ token?: string;
192
+ }): Promise<{
193
+ url: string;
194
+ port: number;
195
+ name: string | undefined;
196
+ }>;
197
+ unexposePort(port: number): Promise<void>;
198
+ }
199
+ export declare class ExecutionSession {
200
+ private readonly sandbox;
201
+ readonly id: string;
202
+ private options;
203
+ constructor(sandbox: Sandbox, id: string, options: SessionOptions);
204
+ private context;
205
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
206
+ execStream(command: string, options?: ExecOptions): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
207
+ startProcess(command: string, options?: ProcessOptions): Promise<Process>;
208
+ private path;
209
+ writeFile(path: string, content: string | ReadableStream<Uint8Array>, options?: {
210
+ encoding?: string;
211
+ }): Promise<{
212
+ success: boolean;
213
+ path: string;
214
+ bytesWritten: number;
215
+ timestamp: string;
216
+ }>;
217
+ readFile(path: string, options: {
218
+ encoding: "none";
219
+ }): Promise<ReadFileStreamResult>;
220
+ readFile(path: string, options?: {
221
+ encoding?: "utf8" | "utf-8" | "base64";
222
+ }): Promise<ReadFileResult>;
223
+ mkdir(path: string, options?: {
224
+ recursive?: boolean;
225
+ }): Promise<{
226
+ success: boolean;
227
+ path: string;
228
+ timestamp: string;
229
+ }>;
230
+ deleteFile(path: string): Promise<{
231
+ success: boolean;
232
+ path: string;
233
+ timestamp: string;
234
+ }>;
235
+ renameFile(path: string, newPath: string): Promise<{
236
+ success: boolean;
237
+ path: string;
238
+ newPath: string;
239
+ timestamp: string;
240
+ }>;
241
+ exists(path: string): Promise<{
242
+ success: boolean;
243
+ path: string;
244
+ exists: boolean;
245
+ timestamp: string;
246
+ }>;
247
+ listFiles(path: string, options?: {
248
+ recursive?: boolean;
249
+ includeHidden?: boolean;
250
+ }): Promise<{
251
+ success: boolean;
252
+ path: string;
253
+ files: {
254
+ absolutePath: string;
255
+ relativePath: string;
256
+ permissions: {
257
+ readable: boolean;
258
+ writable: boolean;
259
+ executable: boolean;
260
+ };
261
+ name: string;
262
+ path: string;
263
+ type: "file" | "directory" | "symlink" | "other";
264
+ size: number;
265
+ mode: string;
266
+ modifiedAt: string;
267
+ uid?: number;
268
+ gid?: number;
269
+ owner?: string;
270
+ group?: string;
271
+ symlinkTarget?: string;
272
+ }[];
273
+ count: number;
274
+ timestamp: string;
275
+ }>;
276
+ setEnvVars(env: Record<string, string | undefined>): Promise<void>;
277
+ }
278
+ export declare class Process {
279
+ private readonly sandbox;
280
+ private readonly native;
281
+ readonly sessionId?: string | undefined;
282
+ constructor(sandbox: Sandbox, native: NativeProcess, sessionId?: string | undefined);
283
+ get id(): string;
284
+ get command(): string;
285
+ get status(): "running" | "killed" | "unknown" | "failed" | "completed";
286
+ get startTime(): Date;
287
+ get endTime(): Date | undefined;
288
+ get exitCode(): number | undefined;
289
+ kill(signal?: string): Promise<void>;
290
+ getStatus(): Promise<"running" | "killed" | "unknown" | "failed" | "completed">;
291
+ getLogs(): Promise<{
292
+ stdout: string;
293
+ stderr: string;
294
+ processId: string;
295
+ }>;
296
+ waitForExit(timeout?: number): Promise<{
297
+ exitCode: number;
298
+ }>;
299
+ waitForLog(pattern: string | RegExp, timeout?: number): Promise<{
300
+ match?: true | RegExpMatchArray | undefined;
301
+ line: string;
302
+ }>;
303
+ }