tensorlake 0.5.13 → 0.5.17

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.
@@ -219,6 +219,12 @@ interface SandboxPoolInfo {
219
219
  createdAt?: Date;
220
220
  updatedAt?: Date;
221
221
  }
222
+ interface ProcessUserSpec {
223
+ name?: string;
224
+ uid?: number;
225
+ gid?: number;
226
+ }
227
+ type ProcessUser = string | ProcessUserSpec;
222
228
  interface StartProcessOptions {
223
229
  args?: string[];
224
230
  env?: Record<string, string>;
@@ -226,6 +232,7 @@ interface StartProcessOptions {
226
232
  stdinMode?: StdinMode;
227
233
  stdoutMode?: OutputMode;
228
234
  stderrMode?: OutputMode;
235
+ user?: ProcessUser;
229
236
  }
230
237
  interface ProcessInfo {
231
238
  pid: number;
@@ -256,6 +263,7 @@ interface RunOptions {
256
263
  env?: Record<string, string>;
257
264
  workingDir?: string;
258
265
  timeout?: number;
266
+ user?: ProcessUser;
259
267
  }
260
268
  interface CommandResult {
261
269
  exitCode: number;
@@ -426,11 +434,13 @@ interface BuildSandbox {
426
434
  env?: Record<string, string>;
427
435
  workingDir?: string;
428
436
  timeout?: number;
437
+ user?: ProcessUser;
429
438
  }): Promise<CommandResult>;
430
439
  startProcess(command: string, options?: {
431
440
  args?: string[];
432
441
  env?: Record<string, string>;
433
442
  workingDir?: string;
443
+ user?: ProcessUser;
434
444
  }): Promise<ProcessInfo>;
435
445
  getStdout(pid: number): Promise<OutputResponse>;
436
446
  getStderr(pid: number): Promise<OutputResponse>;
@@ -464,4 +474,4 @@ declare function registerImage(context: BuildContext, name: string, dockerfile:
464
474
  declare function createSandboxImage(source: SandboxImageSource, options?: CreateSandboxImageOptions, deps?: CreateSandboxImageDeps): Promise<Record<string, unknown>>;
465
475
  declare function runCreateSandboxImageCli(argv?: string[]): Promise<void>;
466
476
 
467
- export { type SnapshotWaitCondition as $, type ArchivedSandboxInfo as A, type ContainerResourcesInfo as B, type CreatePtySessionOptions as C, type DaemonInfo as D, ContainerState as E, type CreateSandboxImageOptions as F, type DirectoryEntry as G, type HealthResponse as H, type DockerfileBuildPlan as I, type DockerfileInstruction as J, Image as K, type ListDirectoryResponse as L, type ImageBuildOperation as M, ImageBuildOperationType as N, type OutputResponse as O, type ProcessInfo as P, type ImageOptions as Q, type RunOptions as R, type SandboxOptions as S, type NetworkConfig as T, type UpdateSandboxOptions as U, OutputMode as V, type PoolContainerInfo as W, ProcessStatus as X, type SandboxImageSource as Y, SnapshotStatus as Z, type SnapshotType as _, type CreateAndConnectOptions as a, StdinMode as a0, createSandboxImage as a1, dockerfileContent as a2, type BuildContext as a3, defaultRegisteredName as a4, loadDockerfilePlan as a5, loadImagePlan as a6, logicalDockerfileLines as a7, registerImage as a8, runCreateSandboxImageCli as a9, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d, type SandboxInfo as e, SandboxStatus as f, type SuspendResumeOptions as g, type CheckpointOptions as h, type CommandResult as i, type StartProcessOptions as j, type SendSignalResponse as k, type OutputEvent as l, type PtySessionInfo as m, type CreateSandboxOptions as n, type CreateSandboxResponse as o, type ListArchivedSandboxesOptions as p, type ListArchivedSandboxesResponse as q, type SandboxPortAccess as r, type SnapshotOptions as s, type CreateSnapshotResponse as t, type SnapshotAndWaitOptions as u, type CreatePoolOptions as v, type CreateSandboxPoolResponse as w, type SandboxPoolInfo as x, type UpdatePoolOptions as y, type CheckpointType as z };
477
+ export { SnapshotStatus as $, type ArchivedSandboxInfo as A, type ContainerResourcesInfo as B, type CreatePtySessionOptions as C, type DaemonInfo as D, ContainerState as E, type CreateSandboxImageOptions as F, type DirectoryEntry as G, type HealthResponse as H, type DockerfileBuildPlan as I, type DockerfileInstruction as J, Image as K, type ListDirectoryResponse as L, type ImageBuildOperation as M, ImageBuildOperationType as N, type OutputResponse as O, type ProcessInfo as P, type ImageOptions as Q, type RunOptions as R, type SandboxOptions as S, type NetworkConfig as T, type UpdateSandboxOptions as U, OutputMode as V, type PoolContainerInfo as W, ProcessStatus as X, type ProcessUser as Y, type ProcessUserSpec as Z, type SandboxImageSource as _, type CreateAndConnectOptions as a, type SnapshotType as a0, type SnapshotWaitCondition as a1, StdinMode as a2, createSandboxImage as a3, dockerfileContent as a4, type BuildContext as a5, defaultRegisteredName as a6, loadDockerfilePlan as a7, loadImagePlan as a8, logicalDockerfileLines as a9, registerImage as aa, runCreateSandboxImageCli as ab, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d, type SandboxInfo as e, SandboxStatus as f, type SuspendResumeOptions as g, type CheckpointOptions as h, type CommandResult as i, type StartProcessOptions as j, type SendSignalResponse as k, type OutputEvent as l, type PtySessionInfo as m, type CreateSandboxOptions as n, type CreateSandboxResponse as o, type ListArchivedSandboxesOptions as p, type ListArchivedSandboxesResponse as q, type SandboxPortAccess as r, type SnapshotOptions as s, type CreateSnapshotResponse as t, type SnapshotAndWaitOptions as u, type CreatePoolOptions as v, type CreateSandboxPoolResponse as w, type SandboxPoolInfo as x, type UpdatePoolOptions as y, type CheckpointType as z };
@@ -219,6 +219,12 @@ interface SandboxPoolInfo {
219
219
  createdAt?: Date;
220
220
  updatedAt?: Date;
221
221
  }
222
+ interface ProcessUserSpec {
223
+ name?: string;
224
+ uid?: number;
225
+ gid?: number;
226
+ }
227
+ type ProcessUser = string | ProcessUserSpec;
222
228
  interface StartProcessOptions {
223
229
  args?: string[];
224
230
  env?: Record<string, string>;
@@ -226,6 +232,7 @@ interface StartProcessOptions {
226
232
  stdinMode?: StdinMode;
227
233
  stdoutMode?: OutputMode;
228
234
  stderrMode?: OutputMode;
235
+ user?: ProcessUser;
229
236
  }
230
237
  interface ProcessInfo {
231
238
  pid: number;
@@ -256,6 +263,7 @@ interface RunOptions {
256
263
  env?: Record<string, string>;
257
264
  workingDir?: string;
258
265
  timeout?: number;
266
+ user?: ProcessUser;
259
267
  }
260
268
  interface CommandResult {
261
269
  exitCode: number;
@@ -426,11 +434,13 @@ interface BuildSandbox {
426
434
  env?: Record<string, string>;
427
435
  workingDir?: string;
428
436
  timeout?: number;
437
+ user?: ProcessUser;
429
438
  }): Promise<CommandResult>;
430
439
  startProcess(command: string, options?: {
431
440
  args?: string[];
432
441
  env?: Record<string, string>;
433
442
  workingDir?: string;
443
+ user?: ProcessUser;
434
444
  }): Promise<ProcessInfo>;
435
445
  getStdout(pid: number): Promise<OutputResponse>;
436
446
  getStderr(pid: number): Promise<OutputResponse>;
@@ -464,4 +474,4 @@ declare function registerImage(context: BuildContext, name: string, dockerfile:
464
474
  declare function createSandboxImage(source: SandboxImageSource, options?: CreateSandboxImageOptions, deps?: CreateSandboxImageDeps): Promise<Record<string, unknown>>;
465
475
  declare function runCreateSandboxImageCli(argv?: string[]): Promise<void>;
466
476
 
467
- export { type SnapshotWaitCondition as $, type ArchivedSandboxInfo as A, type ContainerResourcesInfo as B, type CreatePtySessionOptions as C, type DaemonInfo as D, ContainerState as E, type CreateSandboxImageOptions as F, type DirectoryEntry as G, type HealthResponse as H, type DockerfileBuildPlan as I, type DockerfileInstruction as J, Image as K, type ListDirectoryResponse as L, type ImageBuildOperation as M, ImageBuildOperationType as N, type OutputResponse as O, type ProcessInfo as P, type ImageOptions as Q, type RunOptions as R, type SandboxOptions as S, type NetworkConfig as T, type UpdateSandboxOptions as U, OutputMode as V, type PoolContainerInfo as W, ProcessStatus as X, type SandboxImageSource as Y, SnapshotStatus as Z, type SnapshotType as _, type CreateAndConnectOptions as a, StdinMode as a0, createSandboxImage as a1, dockerfileContent as a2, type BuildContext as a3, defaultRegisteredName as a4, loadDockerfilePlan as a5, loadImagePlan as a6, logicalDockerfileLines as a7, registerImage as a8, runCreateSandboxImageCli as a9, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d, type SandboxInfo as e, SandboxStatus as f, type SuspendResumeOptions as g, type CheckpointOptions as h, type CommandResult as i, type StartProcessOptions as j, type SendSignalResponse as k, type OutputEvent as l, type PtySessionInfo as m, type CreateSandboxOptions as n, type CreateSandboxResponse as o, type ListArchivedSandboxesOptions as p, type ListArchivedSandboxesResponse as q, type SandboxPortAccess as r, type SnapshotOptions as s, type CreateSnapshotResponse as t, type SnapshotAndWaitOptions as u, type CreatePoolOptions as v, type CreateSandboxPoolResponse as w, type SandboxPoolInfo as x, type UpdatePoolOptions as y, type CheckpointType as z };
477
+ export { SnapshotStatus as $, type ArchivedSandboxInfo as A, type ContainerResourcesInfo as B, type CreatePtySessionOptions as C, type DaemonInfo as D, ContainerState as E, type CreateSandboxImageOptions as F, type DirectoryEntry as G, type HealthResponse as H, type DockerfileBuildPlan as I, type DockerfileInstruction as J, Image as K, type ListDirectoryResponse as L, type ImageBuildOperation as M, ImageBuildOperationType as N, type OutputResponse as O, type ProcessInfo as P, type ImageOptions as Q, type RunOptions as R, type SandboxOptions as S, type NetworkConfig as T, type UpdateSandboxOptions as U, OutputMode as V, type PoolContainerInfo as W, ProcessStatus as X, type ProcessUser as Y, type ProcessUserSpec as Z, type SandboxImageSource as _, type CreateAndConnectOptions as a, type SnapshotType as a0, type SnapshotWaitCondition as a1, StdinMode as a2, createSandboxImage as a3, dockerfileContent as a4, type BuildContext as a5, defaultRegisteredName as a6, loadDockerfilePlan as a7, loadImagePlan as a8, logicalDockerfileLines as a9, registerImage as aa, runCreateSandboxImageCli as ab, type SandboxClientOptions as b, type ConnectOptions as c, type SnapshotInfo as d, type SandboxInfo as e, SandboxStatus as f, type SuspendResumeOptions as g, type CheckpointOptions as h, type CommandResult as i, type StartProcessOptions as j, type SendSignalResponse as k, type OutputEvent as l, type PtySessionInfo as m, type CreateSandboxOptions as n, type CreateSandboxResponse as o, type ListArchivedSandboxesOptions as p, type ListArchivedSandboxesResponse as q, type SandboxPortAccess as r, type SnapshotOptions as s, type CreateSnapshotResponse as t, type SnapshotAndWaitOptions as u, type CreatePoolOptions as v, type CreateSandboxPoolResponse as w, type SandboxPoolInfo as x, type UpdatePoolOptions as y, type CheckpointType as z };
@@ -83,7 +83,7 @@ var SDK_VERSION, API_URL, API_KEY, NAMESPACE, SANDBOX_PROXY_URL, DEFAULT_HTTP_TI
83
83
  var init_defaults = __esm({
84
84
  "src/defaults.ts"() {
85
85
  "use strict";
86
- SDK_VERSION = "0.5.13";
86
+ SDK_VERSION = "0.5.17";
87
87
  API_URL = process.env.TENSORLAKE_API_URL ?? "https://api.tensorlake.ai";
88
88
  API_KEY = process.env.TENSORLAKE_API_KEY ?? void 0;
89
89
  NAMESPACE = process.env.INDEXIFY_NAMESPACE ?? "default";
@@ -2933,6 +2933,15 @@ var init_url = __esm({
2933
2933
  });
2934
2934
 
2935
2935
  // src/sandbox.ts
2936
+ function processUserPayload(user) {
2937
+ if (user == null) {
2938
+ return DEFAULT_PROCESS_USER;
2939
+ }
2940
+ if (typeof user === "string" && user.trim() === "") {
2941
+ throw new SandboxError("process user must not be empty");
2942
+ }
2943
+ return user;
2944
+ }
2936
2945
  function normalizePtyMessage(message) {
2937
2946
  if (Buffer.isBuffer(message)) return message;
2938
2947
  if (Array.isArray(message)) {
@@ -2956,7 +2965,7 @@ function sendPtyFrame(socket, frame) {
2956
2965
  socket.send(frame, (error) => error ? reject(error) : resolve());
2957
2966
  });
2958
2967
  }
2959
- var import_ws2, PTY_OP_DATA, PTY_OP_RESIZE, PTY_OP_READY, PTY_OP_EXIT, Pty, Sandbox;
2968
+ var import_ws2, DEFAULT_PROCESS_USER, PTY_OP_DATA, PTY_OP_RESIZE, PTY_OP_READY, PTY_OP_EXIT, Pty, Sandbox;
2960
2969
  var init_sandbox = __esm({
2961
2970
  "src/sandbox.ts"() {
2962
2971
  "use strict";
@@ -2969,6 +2978,7 @@ var init_sandbox = __esm({
2969
2978
  init_sse();
2970
2979
  init_url();
2971
2980
  import_ws2 = __toESM(require("ws"), 1);
2981
+ DEFAULT_PROCESS_USER = "tl-user";
2972
2982
  PTY_OP_DATA = 0;
2973
2983
  PTY_OP_RESIZE = 1;
2974
2984
  PTY_OP_READY = 2;
@@ -3389,6 +3399,8 @@ var init_sandbox = __esm({
3389
3399
  if (options?.env) body.env = options.env;
3390
3400
  if (options?.workingDir) body.working_dir = options.workingDir;
3391
3401
  if (options?.timeout != null) body.timeout = options.timeout;
3402
+ const user = processUserPayload(options?.user);
3403
+ body.user = user;
3392
3404
  const sseStream = await this.http.requestStream(
3393
3405
  "POST",
3394
3406
  "/api/v1/processes/run",
@@ -3432,6 +3444,8 @@ var init_sandbox = __esm({
3432
3444
  if (options?.args != null) payload.args = options.args;
3433
3445
  if (options?.env != null) payload.env = options.env;
3434
3446
  if (options?.workingDir != null) payload.working_dir = options.workingDir;
3447
+ const user = processUserPayload(options?.user);
3448
+ payload.user = user;
3435
3449
  if (options?.stdinMode != null && options.stdinMode !== "closed" /* CLOSED */) {
3436
3450
  payload.stdin_mode = options.stdinMode;
3437
3451
  }
@@ -4922,12 +4936,16 @@ function optionalNumber(object, key) {
4922
4936
  }
4923
4937
  return value;
4924
4938
  }
4925
- async function runChecked(sandbox, command, args, env, workingDir) {
4926
- const result = await sandbox.run(command, {
4939
+ async function runChecked(sandbox, command, args, env, workingDir, user) {
4940
+ const options = {
4927
4941
  args,
4928
4942
  env,
4929
4943
  workingDir
4930
- });
4944
+ };
4945
+ if (user != null) {
4946
+ options.user = user;
4947
+ }
4948
+ const result = await sandbox.run(command, options);
4931
4949
  if (result.exitCode !== 0) {
4932
4950
  throw new Error(
4933
4951
  `Command '${command} ${args.join(" ")}' failed with exit code ${result.exitCode}`
@@ -4939,7 +4957,8 @@ async function runStreaming(sandbox, emit, sleep3, command, args = [], env, work
4939
4957
  const proc = await sandbox.startProcess(command, {
4940
4958
  args,
4941
4959
  env,
4942
- workingDir
4960
+ workingDir,
4961
+ user: ROOTFS_BUILDER_PROCESS_USER
4943
4962
  });
4944
4963
  let stdoutSeen = 0;
4945
4964
  let stderrSeen = 0;
@@ -4981,13 +5000,37 @@ function emitOutputLines(emit, stream, response, seen) {
4981
5000
  emit({ type: "build_log", stream, message: line });
4982
5001
  }
4983
5002
  }
5003
+ async function ensureRemoteBuildRoot(sandbox) {
5004
+ await runChecked(
5005
+ sandbox,
5006
+ "mkdir",
5007
+ ["-p", REMOTE_BUILD_DIR],
5008
+ void 0,
5009
+ void 0,
5010
+ ROOTFS_BUILDER_PROCESS_USER
5011
+ );
5012
+ await runChecked(
5013
+ sandbox,
5014
+ "chmod",
5015
+ ["0777", REMOTE_BUILD_DIR],
5016
+ void 0,
5017
+ void 0,
5018
+ ROOTFS_BUILDER_PROCESS_USER
5019
+ );
5020
+ }
5021
+ async function ensureRemoteDirectory(sandbox, remotePath) {
5022
+ await runChecked(sandbox, "mkdir", ["-p", remotePath]);
5023
+ }
5024
+ async function ensureRemoteParentDir(sandbox, remotePath) {
5025
+ await ensureRemoteDirectory(sandbox, import_node_path.default.posix.dirname(remotePath));
5026
+ }
4984
5027
  async function copyLocalPathToSandbox(sandbox, localPath, remotePath) {
4985
5028
  const fileStats = await (0, import_promises.stat)(localPath).catch(() => null);
4986
5029
  if (!fileStats) {
4987
5030
  throw new Error(`Local path not found: ${localPath}`);
4988
5031
  }
4989
5032
  if (fileStats.isFile()) {
4990
- await runChecked(sandbox, "mkdir", ["-p", import_node_path.default.posix.dirname(remotePath)]);
5033
+ await ensureRemoteParentDir(sandbox, remotePath);
4991
5034
  await sandbox.writeFile(remotePath, await (0, import_promises.readFile)(localPath));
4992
5035
  return;
4993
5036
  }
@@ -4999,14 +5042,10 @@ async function copyLocalPathToSandbox(sandbox, localPath, remotePath) {
4999
5042
  const sourcePath = import_node_path.default.join(localPath, entry.name);
5000
5043
  const destinationPath = import_node_path.default.posix.join(remotePath, entry.name);
5001
5044
  if (entry.isDirectory()) {
5002
- await runChecked(sandbox, "mkdir", ["-p", destinationPath]);
5045
+ await ensureRemoteDirectory(sandbox, destinationPath);
5003
5046
  await copyLocalPathToSandbox(sandbox, sourcePath, destinationPath);
5004
5047
  } else if (entry.isFile()) {
5005
- await runChecked(
5006
- sandbox,
5007
- "mkdir",
5008
- ["-p", import_node_path.default.posix.dirname(destinationPath)]
5009
- );
5048
+ await ensureRemoteParentDir(sandbox, destinationPath);
5010
5049
  await sandbox.writeFile(destinationPath, await (0, import_promises.readFile)(sourcePath));
5011
5050
  }
5012
5051
  }
@@ -5103,6 +5142,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
5103
5142
  message: `Rootfs builder sandbox ${sandbox.sandboxId} is running`
5104
5143
  });
5105
5144
  emit({ type: "status", message: "Uploading build context..." });
5145
+ await ensureRemoteBuildRoot(sandbox);
5106
5146
  await copyLocalPathToSandbox(sandbox, plan.contextDir, REMOTE_CONTEXT_DIR);
5107
5147
  const spec = await buildRootfsSpec(
5108
5148
  preparedSpec,
@@ -5110,7 +5150,7 @@ async function createSandboxImage(source, options = {}, deps = {}) {
5110
5150
  plan,
5111
5151
  options.diskMb
5112
5152
  );
5113
- await runChecked(sandbox, "mkdir", ["-p", import_node_path.default.posix.dirname(REMOTE_SPEC_PATH)]);
5153
+ await ensureRemoteParentDir(sandbox, REMOTE_SPEC_PATH);
5114
5154
  await sandbox.writeFile(
5115
5155
  REMOTE_SPEC_PATH,
5116
5156
  new TextEncoder().encode(JSON.stringify(spec, null, 2))
@@ -5193,7 +5233,7 @@ async function runCreateSandboxImageCli(argv = process.argv.slice(2)) {
5193
5233
  { emit: ndjsonStdoutEmit }
5194
5234
  );
5195
5235
  }
5196
- var import_promises, import_node_os, import_node_path, import_node_util, DEFAULT_ROOTFS_DISK_MB, REMOTE_BUILD_DIR, REMOTE_CONTEXT_DIR, REMOTE_SPEC_PATH, REMOTE_METADATA_PATH, ROOTFS_BUILDER_BIN_DIR, ROOTFS_BUILDER_PATH, ROOTFS_BUILDER_COMMAND, UNSUPPORTED_DOCKERFILE_INSTRUCTIONS;
5236
+ var import_promises, import_node_os, import_node_path, import_node_util, DEFAULT_ROOTFS_DISK_MB, REMOTE_BUILD_DIR, REMOTE_CONTEXT_DIR, REMOTE_SPEC_PATH, REMOTE_METADATA_PATH, ROOTFS_BUILDER_BIN_DIR, ROOTFS_BUILDER_PATH, ROOTFS_BUILDER_COMMAND, ROOTFS_BUILDER_PROCESS_USER, UNSUPPORTED_DOCKERFILE_INSTRUCTIONS;
5197
5237
  var init_sandbox_image = __esm({
5198
5238
  "src/sandbox-image.ts"() {
5199
5239
  import_promises = require("fs/promises");
@@ -5211,6 +5251,7 @@ var init_sandbox_image = __esm({
5211
5251
  ROOTFS_BUILDER_BIN_DIR = "/usr/local/bin";
5212
5252
  ROOTFS_BUILDER_PATH = "/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
5213
5253
  ROOTFS_BUILDER_COMMAND = "tl-rootfs-build";
5254
+ ROOTFS_BUILDER_PROCESS_USER = "root";
5214
5255
  UNSUPPORTED_DOCKERFILE_INSTRUCTIONS = /* @__PURE__ */ new Set([
5215
5256
  "ARG",
5216
5257
  "ONBUILD",