@axiom-lattice/microsandbox-service 2.0.0 → 3.0.1

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.
@@ -260,9 +260,9 @@ var SandboxRegistry = class {
260
260
  const activeSockets = /* @__PURE__ */ new Set();
261
261
  const unixSockets = readFileSync("/proc/net/unix", "utf-8");
262
262
  for (const line of unixSockets.split("\n")) {
263
- const path2 = line.trim().split(" ").pop();
264
- if (path2 && path2.startsWith(SANDBOX_AGENT_SOCKET_DIR)) {
265
- activeSockets.add(path2);
263
+ const path3 = line.trim().split(" ").pop();
264
+ if (path3 && path3.startsWith(SANDBOX_AGENT_SOCKET_DIR)) {
265
+ activeSockets.add(path3);
266
266
  }
267
267
  }
268
268
  for (const entry of readdirSync(SANDBOX_AGENT_SOCKET_DIR)) {
@@ -324,10 +324,10 @@ var SandboxRegistry = class {
324
324
  entry.pausedAt = Date.now();
325
325
  }
326
326
  async healthCheck(native) {
327
- const fs2 = native.fs();
327
+ const fs3 = native.fs();
328
328
  try {
329
329
  await Promise.race([
330
- fs2.list("/"),
330
+ fs3.list("/"),
331
331
  new Promise((_, reject) => setTimeout(() => reject(new Error("health check timed out")), HEALTH_CHECK_TIMEOUT_MS))
332
332
  ]);
333
333
  return true;
@@ -336,11 +336,11 @@ var SandboxRegistry = class {
336
336
  }
337
337
  }
338
338
  async waitForFs(native, maxRetries = 10) {
339
- const fs2 = native.fs();
339
+ const fs3 = native.fs();
340
340
  for (let i = 0; i < maxRetries; i++) {
341
341
  try {
342
342
  await Promise.race([
343
- fs2.list("/"),
343
+ fs3.list("/"),
344
344
  new Promise((_, reject) => setTimeout(() => reject(new Error("FS check timed out")), 5e3))
345
345
  ]);
346
346
  return;
@@ -715,19 +715,19 @@ var MicrosandboxRuntimeService = class {
715
715
  get registry() {
716
716
  return this.deps.registry ?? (this.deps.registry = new SandboxRegistry());
717
717
  }
718
- resolvePath(path2) {
719
- if (path2 === "~" || path2 === "~/") {
718
+ resolvePath(path3) {
719
+ if (path3 === "~" || path3 === "~/") {
720
720
  return "/";
721
721
  }
722
- if (path2.startsWith("~/")) {
723
- return `/${path2.slice(2)}`;
722
+ if (path3.startsWith("~/")) {
723
+ return `/${path3.slice(2)}`;
724
724
  }
725
- return path2;
725
+ return path3;
726
726
  }
727
- resolveDeletePath(path2) {
728
- const resolvedPath = this.resolvePath(path2);
727
+ resolveDeletePath(path3) {
728
+ const resolvedPath = this.resolvePath(path3);
729
729
  if (resolvedPath.replace(/\\/g, "/").split("/").includes("..")) {
730
- throw new HttpError(403, "PATH_TRAVERSAL", `Path traversal denied: ${path2}`);
730
+ throw new HttpError(403, "PATH_TRAVERSAL", `Path traversal denied: ${path3}`);
731
731
  }
732
732
  return resolvedPath;
733
733
  }
@@ -940,22 +940,22 @@ var MicrosandboxRuntimeService = class {
940
940
  resolveProxyTarget(name, port) {
941
941
  return this.registry.getProxyTarget(name, port);
942
942
  }
943
- async readFile(sandboxName, path2) {
944
- const resolvedPath = this.resolvePath(path2);
943
+ async readFile(sandboxName, path3) {
944
+ const resolvedPath = this.resolvePath(path3);
945
945
  const native = await this.getOrEnsureNative(sandboxName);
946
- const fs2 = native.fs();
946
+ const fs3 = native.fs();
947
947
  try {
948
- const content = typeof fs2.readToString === "function" ? await fs2.readToString(resolvedPath) : await fs2.readString(resolvedPath);
948
+ const content = typeof fs3.readToString === "function" ? await fs3.readToString(resolvedPath) : await fs3.readString(resolvedPath);
949
949
  return { path: resolvedPath, content };
950
950
  } catch (error) {
951
951
  if (isFileNotFoundError(error)) {
952
- throw new HttpError(404, "FILE_NOT_FOUND", `File '${path2}' not found`);
952
+ throw new HttpError(404, "FILE_NOT_FOUND", `File '${path3}' not found`);
953
953
  }
954
954
  throw error;
955
955
  }
956
956
  }
957
- async writeFile(sandboxName, path2, content) {
958
- const resolvedPath = this.resolvePath(path2);
957
+ async writeFile(sandboxName, path3, content) {
958
+ const resolvedPath = this.resolvePath(path3);
959
959
  const native = await this.getOrEnsureNative(sandboxName);
960
960
  const parts = resolvedPath.split("/").filter(Boolean);
961
961
  for (let i = 1; i < parts.length; i++) {
@@ -968,8 +968,8 @@ var MicrosandboxRuntimeService = class {
968
968
  await native.fs().write(resolvedPath, Buffer.from(content));
969
969
  return { path: resolvedPath };
970
970
  }
971
- async deleteFile(sandboxName, path2) {
972
- const resolvedPath = this.resolveDeletePath(path2);
971
+ async deleteFile(sandboxName, path3) {
972
+ const resolvedPath = this.resolveDeletePath(path3);
973
973
  const native = await this.getOrEnsureNative(sandboxName);
974
974
  const sandboxFs = native.fs();
975
975
  let metadata;
@@ -977,33 +977,33 @@ var MicrosandboxRuntimeService = class {
977
977
  metadata = await sandboxFs.stat(resolvedPath);
978
978
  } catch (error) {
979
979
  if (isFileNotFoundError(error)) {
980
- throw new HttpError(404, "FILE_NOT_FOUND", `File '${path2}' not found`);
980
+ throw new HttpError(404, "FILE_NOT_FOUND", `File '${path3}' not found`);
981
981
  }
982
982
  const message = error instanceof Error ? error.message : String(error);
983
- throw new HttpError(500, "FILE_STAT_ERROR", `Failed to inspect '${path2}': ${message}`);
983
+ throw new HttpError(500, "FILE_STAT_ERROR", `Failed to inspect '${path3}': ${message}`);
984
984
  }
985
985
  if (metadata.kind === "symlink") {
986
- throw new HttpError(400, "FILE_NOT_REGULAR", `Cannot delete '${path2}': symlinks are not allowed`);
986
+ throw new HttpError(400, "FILE_NOT_REGULAR", `Cannot delete '${path3}': symlinks are not allowed`);
987
987
  }
988
988
  if (metadata.kind === "directory") {
989
- throw new HttpError(400, "FILE_NOT_REGULAR", `Cannot delete '${path2}': target is a directory`);
989
+ throw new HttpError(400, "FILE_NOT_REGULAR", `Cannot delete '${path3}': target is a directory`);
990
990
  }
991
991
  if (metadata.kind !== "file") {
992
- throw new HttpError(400, "FILE_NOT_REGULAR", `Cannot delete '${path2}': target is not a regular file`);
992
+ throw new HttpError(400, "FILE_NOT_REGULAR", `Cannot delete '${path3}': target is not a regular file`);
993
993
  }
994
994
  try {
995
995
  await sandboxFs.remove(resolvedPath);
996
996
  } catch (error) {
997
997
  if (isFileNotFoundError(error)) {
998
- throw new HttpError(404, "FILE_NOT_FOUND", `File '${path2}' not found`);
998
+ throw new HttpError(404, "FILE_NOT_FOUND", `File '${path3}' not found`);
999
999
  }
1000
1000
  const message = error instanceof Error ? error.message : String(error);
1001
- throw new HttpError(500, "FILE_DELETE_ERROR", `Failed to delete '${path2}': ${message}`);
1001
+ throw new HttpError(500, "FILE_DELETE_ERROR", `Failed to delete '${path3}': ${message}`);
1002
1002
  }
1003
1003
  return { path: resolvedPath };
1004
1004
  }
1005
- async listPath(sandboxName, path2, recursive) {
1006
- const resolvedPath = this.resolvePath(path2);
1005
+ async listPath(sandboxName, path3, recursive) {
1006
+ const resolvedPath = this.resolvePath(path3);
1007
1007
  const native = await this.getOrEnsureNative(sandboxName);
1008
1008
  const entries = [];
1009
1009
  const visited = /* @__PURE__ */ new Set();
@@ -1021,15 +1021,15 @@ var MicrosandboxRuntimeService = class {
1021
1021
  await visit(resolvedPath);
1022
1022
  return { entries };
1023
1023
  }
1024
- async findFiles(sandboxName, path2, pattern) {
1025
- const resolvedPath = this.resolvePath(path2);
1024
+ async findFiles(sandboxName, path3, pattern) {
1025
+ const resolvedPath = this.resolvePath(path3);
1026
1026
  const native = await this.getOrEnsureNative(sandboxName);
1027
1027
  const matchFlag = pattern.includes("/") ? "-path" : "-name";
1028
1028
  const output = await native.exec("find", [resolvedPath, matchFlag, pattern, "-type", "f"]);
1029
1029
  return { files: output.stdout().split("\n").filter(Boolean) };
1030
1030
  }
1031
- async searchInFile(sandboxName, path2, query) {
1032
- const resolvedPath = this.resolvePath(path2);
1031
+ async searchInFile(sandboxName, path3, query) {
1032
+ const resolvedPath = this.resolvePath(path3);
1033
1033
  const native = await this.getOrEnsureNative(sandboxName);
1034
1034
  let stdout;
1035
1035
  try {
@@ -1054,8 +1054,8 @@ var MicrosandboxRuntimeService = class {
1054
1054
  async replaceInFile(sandboxName, input) {
1055
1055
  const resolvedPath = this.resolvePath(input.path);
1056
1056
  const native = await this.getOrEnsureNative(sandboxName);
1057
- const fs2 = native.fs();
1058
- const original = typeof fs2.readToString === "function" ? await fs2.readToString(resolvedPath) : await fs2.readString(resolvedPath);
1057
+ const fs3 = native.fs();
1058
+ const original = typeof fs3.readToString === "function" ? await fs3.readToString(resolvedPath) : await fs3.readString(resolvedPath);
1059
1059
  if (!input.search) {
1060
1060
  return { replaced: 0 };
1061
1061
  }
@@ -1064,17 +1064,17 @@ var MicrosandboxRuntimeService = class {
1064
1064
  return { replaced: 0 };
1065
1065
  }
1066
1066
  const updated = original.split(input.search).join(input.replace);
1067
- await fs2.write(resolvedPath, Buffer.from(updated));
1067
+ await fs3.write(resolvedPath, Buffer.from(updated));
1068
1068
  return { replaced: occurrences };
1069
1069
  }
1070
- async uploadFile(sandboxName, path2, contentBase64) {
1071
- const resolvedPath = this.resolvePath(path2);
1070
+ async uploadFile(sandboxName, path3, contentBase64) {
1071
+ const resolvedPath = this.resolvePath(path3);
1072
1072
  const native = await this.getOrEnsureNative(sandboxName);
1073
1073
  await native.fs().write(resolvedPath, Buffer.from(contentBase64, "base64"));
1074
1074
  return { path: resolvedPath };
1075
1075
  }
1076
- async downloadFile(sandboxName, path2) {
1077
- const resolvedPath = this.resolvePath(path2);
1076
+ async downloadFile(sandboxName, path3) {
1077
+ const resolvedPath = this.resolvePath(path3);
1078
1078
  const native = await this.getOrEnsureNative(sandboxName);
1079
1079
  try {
1080
1080
  const data = await native.fs().read(resolvedPath);
@@ -1082,7 +1082,7 @@ var MicrosandboxRuntimeService = class {
1082
1082
  return { path: resolvedPath, contentBase64: buffer.toString("base64") };
1083
1083
  } catch (error) {
1084
1084
  if (isFileNotFoundError(error)) {
1085
- throw new HttpError(404, "FILE_NOT_FOUND", `File '${path2}' not found`);
1085
+ throw new HttpError(404, "FILE_NOT_FOUND", `File '${path3}' not found`);
1086
1086
  }
1087
1087
  throw error;
1088
1088
  }
@@ -1241,8 +1241,8 @@ var ensureSandboxSchema = z2.object({
1241
1241
  image: z2.string().optional(),
1242
1242
  cpus: z2.number().int().positive().optional(),
1243
1243
  memoryMib: z2.number().int().positive().optional(),
1244
- env: z2.record(z2.string()).optional(),
1245
- volumes: z2.record(volumeSchema).optional(),
1244
+ env: z2.record(z2.string(), z2.string()).optional(),
1245
+ volumes: z2.record(z2.string(), volumeSchema).optional(),
1246
1246
  /** Main process command; replaces the default `tail -f /dev/null`. */
1247
1247
  entrypoint: z2.array(z2.string().min(1)).nonempty().optional(),
1248
1248
  /** Absolute lifetime in seconds; `null` means no expiry (caller-managed). */
@@ -1356,11 +1356,11 @@ function filterResponseHeaders(headers) {
1356
1356
  return filtered;
1357
1357
  }
1358
1358
  function pipeRequestUpstream(options) {
1359
- const { target, method, path: path2, headers, body, reply } = options;
1359
+ const { target, method, path: path3, headers, body, reply } = options;
1360
1360
  const { hostname, port } = parseTarget(target);
1361
1361
  return new Promise((resolve, reject) => {
1362
1362
  const upstream = http.request(
1363
- { hostname, port, method, path: path2, headers },
1363
+ { hostname, port, method, path: path3, headers },
1364
1364
  (upstreamResponse) => {
1365
1365
  try {
1366
1366
  reply.code(upstreamResponse.statusCode ?? 502);
@@ -1445,16 +1445,16 @@ function createSandboxController(runtimeService) {
1445
1445
  const { name, port } = request.params;
1446
1446
  const rest = request.params["*"] ?? "";
1447
1447
  const target = runtimeService.resolveProxyTarget(name, Number(port));
1448
- const path2 = `/${rest}`;
1448
+ const path3 = `/${rest}`;
1449
1449
  const headers = buildProxyHeaders(
1450
1450
  request.headers,
1451
- path2
1451
+ path3
1452
1452
  );
1453
1453
  const body = request.body ?? request.raw;
1454
1454
  await pipeRequestUpstream({
1455
1455
  target,
1456
1456
  method: request.method,
1457
- path: path2,
1457
+ path: path3,
1458
1458
  headers,
1459
1459
  body,
1460
1460
  reply
@@ -1565,12 +1565,91 @@ function registerSandboxRoutes(app, runtimeService) {
1565
1565
  }
1566
1566
 
1567
1567
  // src/controllers/volume-fs.ts
1568
- import fs from "fs/promises";
1568
+ import fs2 from "fs/promises";
1569
1569
  import os from "os";
1570
- import path from "path";
1570
+ import path2 from "path";
1571
1571
  import { Volume as Volume2 } from "microsandbox";
1572
1572
  import z4 from "zod";
1573
1573
 
1574
+ // src/lib/volume-path.ts
1575
+ import fs from "fs/promises";
1576
+ import path from "path";
1577
+ var VOLUME_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
1578
+ function pathTraversalError() {
1579
+ return new HttpError(403, "PATH_TRAVERSAL", "Path traversal detected");
1580
+ }
1581
+ function isPathWithin(root, target) {
1582
+ const relative = path.relative(root, target);
1583
+ return relative === "" || relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
1584
+ }
1585
+ function assertPathWithin(root, target) {
1586
+ if (!isPathWithin(root, target)) {
1587
+ throw pathTraversalError();
1588
+ }
1589
+ }
1590
+ function isMissing(error) {
1591
+ return error.code === "ENOENT";
1592
+ }
1593
+ function assertVolumeName(name) {
1594
+ if (name === "." || name === ".." || !VOLUME_NAME_PATTERN.test(name)) {
1595
+ throw new HttpError(400, "INVALID_VOLUME_NAME", "Invalid volume name");
1596
+ }
1597
+ }
1598
+ function resolveGuestPath(hostRoot, guestPath) {
1599
+ if (guestPath.includes("\\") || guestPath.includes("\0")) {
1600
+ throw pathTraversalError();
1601
+ }
1602
+ const normalized = guestPath === "~" ? "" : guestPath.replace(/^~\//, "");
1603
+ if (normalized.split("/").includes("..")) {
1604
+ throw pathTraversalError();
1605
+ }
1606
+ const relative = path.normalize(normalized);
1607
+ if (relative === ".." || relative.startsWith(`..${path.sep}`)) {
1608
+ throw pathTraversalError();
1609
+ }
1610
+ const resolved = path.join(hostRoot, relative);
1611
+ assertPathWithin(hostRoot, resolved);
1612
+ return resolved;
1613
+ }
1614
+ async function resolveContainedGuestPath(hostRoot, guestPath) {
1615
+ const fullPath = resolveGuestPath(hostRoot, guestPath);
1616
+ const [rootReal, fullReal] = await Promise.all([
1617
+ fs.realpath(hostRoot),
1618
+ fs.realpath(fullPath)
1619
+ ]);
1620
+ assertPathWithin(rootReal, fullReal);
1621
+ return fullPath;
1622
+ }
1623
+ async function resolveWritableGuestPath(hostRoot, guestPath) {
1624
+ const fullPath = resolveGuestPath(hostRoot, guestPath);
1625
+ await fs.mkdir(hostRoot, { recursive: true });
1626
+ const rootReal = await fs.realpath(hostRoot);
1627
+ let current = fullPath;
1628
+ while (current !== null) {
1629
+ let exists = true;
1630
+ try {
1631
+ await fs.lstat(current);
1632
+ } catch (error) {
1633
+ if (!isMissing(error)) throw error;
1634
+ exists = false;
1635
+ }
1636
+ if (exists) {
1637
+ let ancestorReal;
1638
+ try {
1639
+ ancestorReal = await fs.realpath(current);
1640
+ } catch (error) {
1641
+ if (isMissing(error)) throw pathTraversalError();
1642
+ throw error;
1643
+ }
1644
+ assertPathWithin(rootReal, ancestorReal);
1645
+ return fullPath;
1646
+ }
1647
+ const parent = path.dirname(current);
1648
+ current = parent === current ? null : parent;
1649
+ }
1650
+ throw pathTraversalError();
1651
+ }
1652
+
1574
1653
  // src/schemas/volume-fs.ts
1575
1654
  import z3 from "zod";
1576
1655
  var volumeFsReadSchema = z3.object({
@@ -1586,9 +1665,15 @@ var volumeFsDeleteSchema = z3.object({
1586
1665
  var volumeFsListSchema = z3.object({
1587
1666
  path: z3.string()
1588
1667
  });
1668
+ function isBase64(value) {
1669
+ if (value.length % 4 === 1) return false;
1670
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value)) return false;
1671
+ if (value.includes("=") && value.length % 4 !== 0) return false;
1672
+ return true;
1673
+ }
1589
1674
  var volumeFsUploadSchema = z3.object({
1590
1675
  path: z3.string(),
1591
- contentBase64: z3.string().min(1)
1676
+ contentBase64: z3.string().min(1).refine(isBase64, { message: "Invalid base64 content" })
1592
1677
  });
1593
1678
  var volumeFsDownloadSchema = z3.object({
1594
1679
  path: z3.string()
@@ -1598,13 +1683,7 @@ var volumeFsMkdirSchema = z3.object({
1598
1683
  });
1599
1684
 
1600
1685
  // src/controllers/volume-fs.ts
1601
- var MSB_DATA_DIR = path.join(os.homedir(), ".microsandbox");
1602
- var VOLUME_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
1603
- function assertVolumeName(name) {
1604
- if (name === "." || name === ".." || !VOLUME_NAME_PATTERN.test(name)) {
1605
- throw new HttpError(400, "INVALID_VOLUME_NAME", "Invalid volume name");
1606
- }
1607
- }
1686
+ var MSB_DATA_DIR = path2.join(os.homedir(), ".microsandbox");
1608
1687
  function assertRegularVolumeFile(guestPath, stat) {
1609
1688
  if (stat.isSymbolicLink()) {
1610
1689
  throw new HttpError(
@@ -1640,32 +1719,17 @@ async function resolveVolumeHostPath(name) {
1640
1719
  const vol = await Volume2.builder(name).create();
1641
1720
  return vol.path;
1642
1721
  } catch {
1643
- return path.join(MSB_DATA_DIR, "volumes", name);
1722
+ return path2.join(MSB_DATA_DIR, "volumes", name);
1644
1723
  }
1645
1724
  }
1646
1725
  }
1647
- function resolveGuestPath(hostRoot, guestPath) {
1648
- const normalized = guestPath === "~" ? "" : guestPath.replace(/^~\//, "");
1649
- const resolved = path.join(hostRoot, path.normalize(normalized).replace(/^(\.\.(\/|\\|$))+/, ""));
1650
- if (!resolved.startsWith(hostRoot + path.sep) && resolved !== hostRoot) {
1651
- throw new HttpError(403, "PATH_TRAVERSAL", "Path traversal detected");
1652
- }
1653
- return resolved;
1654
- }
1655
- function resolveDeleteGuestPath(hostRoot, guestPath) {
1656
- const pathSegments = guestPath.replace(/\\/g, "/").split("/");
1657
- if (pathSegments.includes("..")) {
1658
- throw new HttpError(403, "PATH_TRAVERSAL", "Path traversal detected");
1659
- }
1660
- return resolveGuestPath(hostRoot, guestPath);
1661
- }
1662
1726
  async function assertDeleteParentContained(hostRoot, fullPath) {
1663
1727
  const [rootPath, parentPath] = await Promise.all([
1664
- fs.realpath(hostRoot),
1665
- fs.realpath(path.dirname(fullPath))
1728
+ fs2.realpath(hostRoot),
1729
+ fs2.realpath(path2.dirname(fullPath))
1666
1730
  ]);
1667
- const relative = path.relative(rootPath, parentPath);
1668
- if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
1731
+ const relative = path2.relative(rootPath, parentPath);
1732
+ if (relative === ".." || relative.startsWith(`..${path2.sep}`) || path2.isAbsolute(relative)) {
1669
1733
  throw new HttpError(403, "PATH_TRAVERSAL", "Path traversal detected");
1670
1734
  }
1671
1735
  }
@@ -1676,8 +1740,8 @@ function createVolumeFsController() {
1676
1740
  try {
1677
1741
  const { path: guestPath } = volumeFsReadSchema.parse(request.body ?? {});
1678
1742
  const hostRoot = await resolveVolumeHostPath(name);
1679
- const fullPath = resolveGuestPath(hostRoot, guestPath);
1680
- const content = await fs.readFile(fullPath, "utf-8");
1743
+ const fullPath = await resolveContainedGuestPath(hostRoot, guestPath);
1744
+ const content = await fs2.readFile(fullPath, "utf-8");
1681
1745
  return reply.send(ok({ path: guestPath, content }));
1682
1746
  } catch (err) {
1683
1747
  if (err instanceof z4.ZodError) {
@@ -1692,9 +1756,9 @@ function createVolumeFsController() {
1692
1756
  try {
1693
1757
  const { path: guestPath, content } = volumeFsWriteSchema.parse(request.body ?? {});
1694
1758
  const hostRoot = await resolveVolumeHostPath(name);
1695
- const fullPath = resolveGuestPath(hostRoot, guestPath);
1696
- await fs.mkdir(path.dirname(fullPath), { recursive: true });
1697
- await fs.writeFile(fullPath, content, "utf-8");
1759
+ const fullPath = await resolveWritableGuestPath(hostRoot, guestPath);
1760
+ await fs2.mkdir(path2.dirname(fullPath), { recursive: true });
1761
+ await fs2.writeFile(fullPath, content, "utf-8");
1698
1762
  return reply.send(ok({ path: guestPath }));
1699
1763
  } catch (err) {
1700
1764
  if (err instanceof z4.ZodError) {
@@ -1709,11 +1773,11 @@ function createVolumeFsController() {
1709
1773
  try {
1710
1774
  const { path: guestPath } = volumeFsDeleteSchema.parse(request.body ?? {});
1711
1775
  const hostRoot = await resolveVolumeHostPath(name);
1712
- const fullPath = resolveDeleteGuestPath(hostRoot, guestPath);
1776
+ const fullPath = resolveGuestPath(hostRoot, guestPath);
1713
1777
  await assertDeleteParentContained(hostRoot, fullPath);
1714
- const stat = await fs.lstat(fullPath);
1778
+ const stat = await fs2.lstat(fullPath);
1715
1779
  assertRegularVolumeFile(guestPath, stat);
1716
- const currentStat = await fs.lstat(fullPath);
1780
+ const currentStat = await fs2.lstat(fullPath);
1717
1781
  assertRegularVolumeFile(guestPath, currentStat);
1718
1782
  if (currentStat.dev !== stat.dev || currentStat.ino !== stat.ino) {
1719
1783
  throw new HttpError(
@@ -1723,7 +1787,7 @@ function createVolumeFsController() {
1723
1787
  );
1724
1788
  }
1725
1789
  await assertDeleteParentContained(hostRoot, fullPath);
1726
- await fs.unlink(fullPath);
1790
+ await fs2.unlink(fullPath);
1727
1791
  return reply.send(ok({ path: guestPath }));
1728
1792
  } catch (err) {
1729
1793
  if (err instanceof z4.ZodError) {
@@ -1749,15 +1813,15 @@ function createVolumeFsController() {
1749
1813
  try {
1750
1814
  const { path: guestPath } = volumeFsListSchema.parse(request.body ?? {});
1751
1815
  const hostRoot = await resolveVolumeHostPath(name);
1752
- const fullPath = resolveGuestPath(hostRoot, guestPath);
1753
- const dirents = await fs.readdir(fullPath, { withFileTypes: true });
1816
+ const fullPath = await resolveContainedGuestPath(hostRoot, guestPath);
1817
+ const dirents = await fs2.readdir(fullPath, { withFileTypes: true });
1754
1818
  const entries = [];
1755
1819
  for (const d of dirents) {
1756
1820
  let size = 0;
1757
1821
  let modified = null;
1758
1822
  let created = null;
1759
1823
  try {
1760
- const stat = await fs.lstat(path.join(fullPath, d.name));
1824
+ const stat = await fs2.lstat(path2.join(fullPath, d.name));
1761
1825
  size = stat.size;
1762
1826
  modified = stat.mtime.toISOString();
1763
1827
  created = stat.birthtime.getTime() > 0 ? stat.birthtime.toISOString() : null;
@@ -1786,8 +1850,8 @@ function createVolumeFsController() {
1786
1850
  try {
1787
1851
  const { path: guestPath } = volumeFsDownloadSchema.parse(request.query ?? {});
1788
1852
  const hostRoot = await resolveVolumeHostPath(name);
1789
- const fullPath = resolveGuestPath(hostRoot, guestPath);
1790
- const buf = await fs.readFile(fullPath);
1853
+ const fullPath = await resolveContainedGuestPath(hostRoot, guestPath);
1854
+ const buf = await fs2.readFile(fullPath);
1791
1855
  const contentBase64 = buf.toString("base64");
1792
1856
  return reply.send(ok({ path: guestPath, contentBase64 }));
1793
1857
  } catch (err) {
@@ -1803,10 +1867,10 @@ function createVolumeFsController() {
1803
1867
  try {
1804
1868
  const { path: guestPath, contentBase64 } = volumeFsUploadSchema.parse(request.body ?? {});
1805
1869
  const hostRoot = await resolveVolumeHostPath(name);
1806
- const fullPath = resolveGuestPath(hostRoot, guestPath);
1807
- await fs.mkdir(path.dirname(fullPath), { recursive: true });
1870
+ const fullPath = await resolveWritableGuestPath(hostRoot, guestPath);
1871
+ await fs2.mkdir(path2.dirname(fullPath), { recursive: true });
1808
1872
  const data = Buffer.from(contentBase64, "base64");
1809
- await fs.writeFile(fullPath, data);
1873
+ await fs2.writeFile(fullPath, data);
1810
1874
  return reply.send(ok({ path: guestPath }));
1811
1875
  } catch (err) {
1812
1876
  if (err instanceof z4.ZodError) {
@@ -1821,8 +1885,8 @@ function createVolumeFsController() {
1821
1885
  try {
1822
1886
  const { path: guestPath } = volumeFsMkdirSchema.parse(request.body ?? {});
1823
1887
  const hostRoot = await resolveVolumeHostPath(name);
1824
- const fullPath = resolveGuestPath(hostRoot, guestPath);
1825
- await fs.mkdir(fullPath, { recursive: true });
1888
+ const fullPath = await resolveWritableGuestPath(hostRoot, guestPath);
1889
+ await fs2.mkdir(fullPath, { recursive: true });
1826
1890
  return reply.send(ok({ path: guestPath }));
1827
1891
  } catch (err) {
1828
1892
  if (err instanceof z4.ZodError) {
@@ -2017,4 +2081,4 @@ export {
2017
2081
  MicrosandboxRuntimeService,
2018
2082
  buildApp
2019
2083
  };
2020
- //# sourceMappingURL=chunk-F4FMPABT.mjs.map
2084
+ //# sourceMappingURL=chunk-LJIZCKJ4.mjs.map