ppio-sandbox 2.1.1-a7 → 2.1.2

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
@@ -89,3 +89,22 @@ await desktop.leftClick(100, 200);
89
89
  await desktop.press('Enter');
90
90
  await desktop.write('Hello, World!');
91
91
  ```
92
+
93
+
94
+ ### Template environment scope
95
+
96
+ `setEnvs({...})` adds build-only variables. To retain values in the sandbox, use
97
+ `setEnvs({...}, { runtime: true })`. Dockerfile `ENV` is persisted at runtime;
98
+ Dockerfile `ARG` remains build-only. Declarations are evaluated in order, with
99
+ values in one group reading the preceding environment. Image ENV is literal,
100
+ and inherited WORKDIR applies before caller steps.
101
+
102
+ ```typescript
103
+ const template = Template().fromImage("python:3.12-slim");
104
+ template.setEnvs({ BUILD_MODE: "release" });
105
+ template.setEnvs({ PATH: "/app/bin:$PATH", APP_MODE: "worker" }, { runtime: true });
106
+ ```
107
+
108
+ Mutable image tags are refreshed for each serialization/build. Only successful
109
+ digest-pinned registry reads are cached, and failed reads are retryable on the
110
+ same builder. Explicit caller commands and settings override image defaults.
@@ -9,7 +9,7 @@ import {
9
9
  __forAwait,
10
10
  __spreadProps,
11
11
  __spreadValues
12
- } from "./chunk-3FDSHOTR.mjs";
12
+ } from "./chunk-PQGBLWKQ.mjs";
13
13
 
14
14
  // src/code-interpreter/messaging.ts
15
15
  async function extractError(res) {
@@ -465,4 +465,4 @@ Sandbox2.defaultTemplate = "code-interpreter-v1";
465
465
  export {
466
466
  Sandbox2 as Sandbox
467
467
  };
468
- //# sourceMappingURL=chunk-2JB7PIKB.mjs.map
468
+ //# sourceMappingURL=chunk-3L3K3WO3.mjs.map
@@ -5,7 +5,7 @@ import {
5
5
  TimeoutError,
6
6
  __spreadProps,
7
7
  __spreadValues
8
- } from "./chunk-3FDSHOTR.mjs";
8
+ } from "./chunk-PQGBLWKQ.mjs";
9
9
 
10
10
  // src/desktop/utils.ts
11
11
  import { randomBytes } from "crypto";
@@ -530,4 +530,4 @@ var VNCServer = class {
530
530
  export {
531
531
  Sandbox2 as Sandbox
532
532
  };
533
- //# sourceMappingURL=chunk-5OUOMKUS.mjs.map
533
+ //# sourceMappingURL=chunk-3OWF5GCM.mjs.map
@@ -60,7 +60,7 @@ import createClient from "openapi-fetch";
60
60
  import platform2 from "platform";
61
61
 
62
62
  // package.json
63
- var version = "2.1.1-a7";
63
+ var version = "2.1.2";
64
64
 
65
65
  // src/core/utils.ts
66
66
  import platform from "platform";
@@ -5491,54 +5491,15 @@ function handleUserInstruction(instruction, templateBuilder) {
5491
5491
  }
5492
5492
  }
5493
5493
  function handleEnvInstruction(instruction, templateBuilder) {
5494
- const argumentsData = instruction.getArguments();
5495
- const keyword = instruction.getKeyword();
5496
- if (argumentsData && argumentsData.length >= 1) {
5497
- const envVars = {};
5498
- if (argumentsData.length === 2) {
5499
- const firstArg = argumentsData[0].getValue();
5500
- const secondArg = argumentsData[1].getValue();
5501
- if (firstArg.includes("=") && secondArg.includes("=")) {
5502
- for (const arg of argumentsData) {
5503
- const envString = arg.getValue();
5504
- const equalIndex = envString.indexOf("=");
5505
- if (equalIndex > 0) {
5506
- const key = envString.substring(0, equalIndex);
5507
- const value = envString.substring(equalIndex + 1);
5508
- envVars[key] = value;
5509
- }
5510
- }
5511
- } else {
5512
- envVars[firstArg] = secondArg;
5513
- }
5514
- } else if (argumentsData.length === 1) {
5515
- const envString = argumentsData[0].getValue();
5516
- const equalIndex = envString.indexOf("=");
5517
- if (equalIndex > 0) {
5518
- const key = envString.substring(0, equalIndex);
5519
- const value = envString.substring(equalIndex + 1);
5520
- envVars[key] = value;
5521
- } else if (keyword === "ARG" && envString.trim()) {
5522
- const key = envString.trim();
5523
- envVars[key] = "";
5524
- }
5525
- } else {
5526
- for (const arg of argumentsData) {
5527
- const envString = arg.getValue();
5528
- const equalIndex = envString.indexOf("=");
5529
- if (equalIndex > 0) {
5530
- const key = envString.substring(0, equalIndex);
5531
- const value = envString.substring(equalIndex + 1);
5532
- envVars[key] = value;
5533
- } else if (keyword === "ARG") {
5534
- const key = envString;
5535
- envVars[key] = "";
5536
- }
5537
- }
5538
- }
5539
- if (Object.keys(envVars).length > 0) {
5540
- templateBuilder.setEnvs(envVars);
5541
- }
5494
+ var _a3;
5495
+ const envVars = {};
5496
+ for (const property of instruction.getProperties()) {
5497
+ envVars[property.getName()] = (_a3 = property.getValue()) != null ? _a3 : "";
5498
+ }
5499
+ if (Object.keys(envVars).length) {
5500
+ templateBuilder.setEnvs(envVars, {
5501
+ runtime: instruction.getKeyword() === "ENV"
5502
+ });
5542
5503
  }
5543
5504
  }
5544
5505
  function handleCmdEntrypointInstruction(instruction, templateBuilder) {
@@ -5560,6 +5521,7 @@ function handleCmdEntrypointInstruction(instruction, templateBuilder) {
5560
5521
  var PROFILE_PATH = "/etc/profile.d/99-image-env.sh";
5561
5522
  var ENVIRONMENT_PATH = "/etc/environment";
5562
5523
  var SCRIPT_PATH = "/tmp/.ppio-image-env.sh";
5524
+ var BASE_ENV_PATH = "/etc/.ppio-image-env-base.sh";
5563
5525
  function unsettableEnvName(name) {
5564
5526
  return !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name);
5565
5527
  }
@@ -5579,54 +5541,112 @@ function expandableDoubleQuote(value) {
5579
5541
  const escaped = value.split("\\").join("\\\\").split('"').join('\\"').split("`").join("\\`").replace(/\$\(/g, "\\$(");
5580
5542
  return `"${escaped}"`;
5581
5543
  }
5582
- function envFilesScript(envs) {
5583
- const lines = [
5584
- "set -e",
5585
- `: > ${PROFILE_PATH}`,
5586
- `: > ${ENVIRONMENT_PATH}`
5587
- ];
5588
- for (const [name, declared] of Object.entries(envs)) {
5544
+ function envFilesScript(envs, literalEnvs = {}, envGroups, baseEnvPath) {
5545
+ const groups = envGroups != null ? envGroups : Object.entries(envs).map(([name, value]) => ({
5546
+ values: { [name]: value },
5547
+ runtime: true
5548
+ }));
5549
+ const lines = String.raw`set -e
5550
+ ${baseEnvPath ? ". " + shellQuote2(baseEnvPath) : ":"}
5551
+ ${baseEnvPath ? "command -p rm -f " + shellQuote2(baseEnvPath) : ":"}
5552
+ if [ -f "${PROFILE_PATH}" ]; then . "${PROFILE_PATH}"; fi
5553
+ command -p touch "${PROFILE_PATH}" "${ENVIRONMENT_PATH}"
5554
+ __ppio_build_env() {
5555
+ while [ "$#" -gt 0 ]; do export "$1=$2"; shift 2; done
5556
+ }
5557
+ __ppio_runtime_env() {
5558
+ while [ "$#" -gt 0 ]; do
5559
+ export "$1=$2"
5560
+ printf "export %s='" "$1" >> ${PROFILE_PATH}
5561
+ printf '%s' "$2" | command -p sed "s/'/'\\\\''/g" >> ${PROFILE_PATH}
5562
+ printf "'\n" >> ${PROFILE_PATH}
5563
+ command -p sed "/^$1=/d" ${ENVIRONMENT_PATH} > ${ENVIRONMENT_PATH}.tmp
5564
+ command -p cat ${ENVIRONMENT_PATH}.tmp > ${ENVIRONMENT_PATH}
5565
+ command -p rm -f ${ENVIRONMENT_PATH}.tmp
5566
+ case "$2" in
5567
+ *'"'*) ;;
5568
+ *) if [ "$(printf '%s' "$2" | command -p wc -l)" -eq 0 ]; then printf '%s=%s\n' "$1" "$2" >> ${ENVIRONMENT_PATH}; fi ;;
5569
+ esac
5570
+ shift 2
5571
+ done
5572
+ }`.split("\n");
5573
+ const quote = (value) => "'" + value.replace(/'/g, "'\\''") + "'";
5574
+ if (Object.keys(literalEnvs).length) {
5575
+ lines.push(
5576
+ "__ppio_runtime_env " + Object.entries(literalEnvs).map(([name, value]) => `${name} ${quote(value)}`).join(" ")
5577
+ );
5578
+ }
5579
+ for (const group of groups) {
5580
+ if (!Object.keys(group.values).length) continue;
5581
+ const fn = group.runtime ? "__ppio_runtime_env" : "__ppio_build_env";
5589
5582
  lines.push(
5590
- // Expand the declared value here, against the build's own environment.
5591
- `v=${expandableDoubleQuote(declared)}`,
5592
- // Export it before moving on, so a later value can reference this one --
5593
- // `ENV VIRTUAL_ENV=/opt/venv PYTHONPATH=$VIRTUAL_ENV/lib` is ordinary, and
5594
- // the platform's own ENV handling cannot be relied on for it (it ignores
5595
- // PATH entirely). Without this the reference expanded to empty.
5596
- `export ${name}="$v"`,
5597
- // profile.d: single-quoted, with any embedded quote closed and reopened.
5598
- `printf "export ${name}='%s'\\n" "$(printf '%s' "$v" | sed "s/'/'\\\\\\\\''/g")" >> ${PROFILE_PATH}`,
5599
- // pam_env: bare, and only when it can represent the value at all.
5600
- 'case "$v" in',
5601
- ` *'"'*) v= ;;`,
5602
- "esac",
5603
- `[ -n "$v" ] && [ "$(printf '%s' "$v" | wc -l)" -eq 0 ] && printf '${name}=%s\\n' "$v" >> ${ENVIRONMENT_PATH}`,
5604
- // `[ ... ] &&` above exits non-zero when the value is skipped, which would
5605
- // abort the script under `set -e`.
5606
- "true"
5583
+ fn + " " + Object.entries(group.values).map(([name, value]) => `${name} ${expandableDoubleQuote(value)}`).join(" ")
5607
5584
  );
5608
5585
  }
5609
- lines.push(`chmod 0644 ${PROFILE_PATH} ${ENVIRONMENT_PATH}`);
5586
+ lines.push(`command -p chmod 0644 ${PROFILE_PATH} ${ENVIRONMENT_PATH}`);
5610
5587
  return lines.join("\n");
5611
5588
  }
5612
- function envFilesCommand(envs) {
5613
- const { usable, skipped } = partitionEnvNames(Object.keys(envs));
5614
- if (usable.length === 0) {
5615
- return { command: null, skipped };
5616
- }
5617
- const script = envFilesScript(
5618
- Object.fromEntries(usable.map((name) => [name, envs[name]]))
5589
+ function envFilesCommand(envs, literalEnvs = {}, envGroups, baseEnvPath) {
5590
+ const groups = envGroups != null ? envGroups : Object.entries(envs).map(([name, value]) => ({
5591
+ values: { [name]: value },
5592
+ runtime: true
5593
+ }));
5594
+ const names = [
5595
+ .../* @__PURE__ */ new Set([
5596
+ ...Object.keys(literalEnvs),
5597
+ ...groups.flatMap((group) => Object.keys(group.values))
5598
+ ])
5599
+ ];
5600
+ const { usable, skipped } = partitionEnvNames(names);
5601
+ const allowed = new Set(usable);
5602
+ const filter = (values) => Object.fromEntries(
5603
+ Object.entries(values).filter(([name]) => allowed.has(name))
5619
5604
  );
5620
- const b64 = Buffer.from(script, "utf8").toString("base64");
5605
+ const literals = filter(literalEnvs);
5606
+ const filtered = groups.map((group) => ({
5607
+ values: filter(group.values),
5608
+ runtime: group.runtime
5609
+ }));
5610
+ if (!Object.keys(literals).length && !filtered.some((group) => group.runtime && Object.keys(group.values).length))
5611
+ return { command: null, skipped };
5612
+ const b64 = Buffer.from(
5613
+ envFilesScript({}, literals, filtered, baseEnvPath),
5614
+ "utf8"
5615
+ ).toString("base64");
5621
5616
  return {
5622
5617
  command: [
5623
- `echo ${b64} | base64 -d > ${SCRIPT_PATH}`,
5624
- `sh ${SCRIPT_PATH}`,
5625
- `rm -f ${SCRIPT_PATH}`
5618
+ `echo ${b64} | command -p base64 -d > ${SCRIPT_PATH}`,
5619
+ `command -p sh ${SCRIPT_PATH}`,
5620
+ `command -p rm -f ${SCRIPT_PATH}`
5626
5621
  ].join(" && "),
5627
5622
  skipped
5628
5623
  };
5629
5624
  }
5625
+ function shellQuote2(value) {
5626
+ return "'" + value.replace(/'/g, "'\\''") + "'";
5627
+ }
5628
+ function envSnapshotCommand(groups) {
5629
+ const { usable } = partitionEnvNames([
5630
+ ...new Set(groups.flatMap((group) => Object.keys(group.values)))
5631
+ ]);
5632
+ if (!usable.length) return null;
5633
+ const lines = [
5634
+ "set -e",
5635
+ "umask 077",
5636
+ `: > ${BASE_ENV_PATH}`,
5637
+ `command -p chmod 0600 ${BASE_ENV_PATH}`
5638
+ ];
5639
+ for (const name of usable) {
5640
+ lines.push(String.raw`if [ "${"${" + name + "+x}"}" = x ]; then
5641
+ printf "export ${name}='" >> ${BASE_ENV_PATH}
5642
+ printf '%s' "${"${" + name + "}"}" | command -p sed "s/'/'\\\\''/g" >> ${BASE_ENV_PATH}
5643
+ printf "'\n" >> ${BASE_ENV_PATH}
5644
+ else
5645
+ printf 'unset ${name}\n' >> ${BASE_ENV_PATH}
5646
+ fi`);
5647
+ }
5648
+ return "command -p sh -c " + shellQuote2(lines.join("\n"));
5649
+ }
5630
5650
 
5631
5651
  // src/core/template/imageConfig.ts
5632
5652
  var HUB_HOST = "registry-1.docker.io";
@@ -5662,9 +5682,15 @@ function unsupportedBase(blob) {
5662
5682
  return null;
5663
5683
  }
5664
5684
  const families = [
5665
- [/alpine-minirootfs|etc\/alpine-release|apk add|apk --no-cache/i, "Alpine (musl)"],
5685
+ [
5686
+ /alpine-minirootfs|etc\/alpine-release|apk add|apk --no-cache/i,
5687
+ "Alpine (musl)"
5688
+ ],
5666
5689
  [/^BusyBox /im, "BusyBox"],
5667
- [/microdnf|dnf install|yum install|rpm -i/i, "RPM-based (Fedora/RHEL/Rocky)"],
5690
+ [
5691
+ /microdnf|dnf install|yum install|rpm -i/i,
5692
+ "RPM-based (Fedora/RHEL/Rocky)"
5693
+ ],
5668
5694
  [/pacman -S/i, "Arch"],
5669
5695
  [/zypper|KIWI /i, "SUSE"]
5670
5696
  ];
@@ -5707,7 +5733,7 @@ function parseImageRef(image) {
5707
5733
  let reference;
5708
5734
  const at = ref.indexOf("@");
5709
5735
  if (at !== -1) {
5710
- repository = ref.slice(0, at);
5736
+ repository = ref.slice(0, at).replace(/:[^/]*$/, "");
5711
5737
  reference = ref.slice(at + 1);
5712
5738
  } else {
5713
5739
  const colon = ref.lastIndexOf(":");
@@ -5828,7 +5854,10 @@ async function registryGet(url, headers, options) {
5828
5854
  for (let attempt = 0; attempt < attempts; attempt++) {
5829
5855
  if (attempt > 0) {
5830
5856
  await new Promise(
5831
- (resolve) => setTimeout(resolve, retryDelayMs(last, 2 ** (attempt - 1) * backoffBaseMs))
5857
+ (resolve) => setTimeout(
5858
+ resolve,
5859
+ retryDelayMs(last, 2 ** (attempt - 1) * backoffBaseMs)
5860
+ )
5832
5861
  );
5833
5862
  }
5834
5863
  try {
@@ -5942,7 +5971,10 @@ var RegistrySession = class {
5942
5971
  if (params.service) {
5943
5972
  url.searchParams.set("service", params.service);
5944
5973
  }
5945
- url.searchParams.set("scope", params.scope || `repository:${this.repository}:pull`);
5974
+ url.searchParams.set(
5975
+ "scope",
5976
+ params.scope || `repository:${this.repository}:pull`
5977
+ );
5946
5978
  const headers = {};
5947
5979
  if (((_a3 = this.credentials) == null ? void 0 : _a3.username) && this.credentials.password) {
5948
5980
  headers.Authorization = basicHeader(this.credentials);
@@ -6019,7 +6051,7 @@ function describeFailure(error, image, host, repository, authenticated) {
6019
6051
  async function fetchImageConfig(image, credentials, options) {
6020
6052
  var _a3, _b, _c, _d, _e, _f, _g;
6021
6053
  const dispatcher = options == null ? void 0 : options.dispatcher;
6022
- const cacheable = dispatcher === void 0;
6054
+ const cacheable = dispatcher === void 0 && image.includes("@");
6023
6055
  const key = JSON.stringify([
6024
6056
  image,
6025
6057
  (_a3 = credentials == null ? void 0 : credentials.username) != null ? _a3 : null,
@@ -6085,7 +6117,7 @@ async function fetchImageConfig(image, credentials, options) {
6085
6117
  Boolean((credentials == null ? void 0 : credentials.username) && (credentials == null ? void 0 : credentials.password))
6086
6118
  );
6087
6119
  }
6088
- if (cacheable) {
6120
+ if (cacheable && !result.error) {
6089
6121
  CACHE.set(key, result);
6090
6122
  }
6091
6123
  return copyConfig(result);
@@ -6095,7 +6127,7 @@ function effectiveStartCmd(entrypoint, cmd) {
6095
6127
  return parts.length > 0 ? parts.map(shellQuoteArg).join(" ") : null;
6096
6128
  }
6097
6129
  function shellQuoteArg(value) {
6098
- return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
6130
+ return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
6099
6131
  }
6100
6132
  function clearImageConfigCache() {
6101
6133
  CACHE.clear();
@@ -6259,6 +6291,8 @@ var TemplateBase = class _TemplateBase {
6259
6291
  // rather than written per call because the file is written once from the full
6260
6292
  // set -- a per-call write would clobber the previous call's file.
6261
6293
  this.envs = {};
6294
+ this.envDeclarations = [];
6295
+ this.imageEnvs = {};
6262
6296
  // Whether to restore what the base image declares -- see fromImage() and
6263
6297
  // resolveInheritedConfig(). Only meaningful for an image base; a Dockerfile
6264
6298
  // states its own ENV/WORKDIR/CMD, and a template base already carries them.
@@ -6533,6 +6567,7 @@ var TemplateBase = class _TemplateBase {
6533
6567
  }
6534
6568
  this.baseImage = baseImage;
6535
6569
  this.baseTemplate = void 0;
6570
+ this.resetInheritedConfig();
6536
6571
  this.inheritImageConfig = (_a3 = options == null ? void 0 : options.inheritConfig) != null ? _a3 : true;
6537
6572
  this.imageCredentials = credentials;
6538
6573
  this.imageOnConfigFailure = (_b = options == null ? void 0 : options.onConfigFailure) != null ? _b : "warn";
@@ -6553,6 +6588,7 @@ var TemplateBase = class _TemplateBase {
6553
6588
  fromTemplate(template) {
6554
6589
  this.baseTemplate = template;
6555
6590
  this.baseImage = void 0;
6591
+ this.resetInheritedConfig();
6556
6592
  if (this.forceNextLayer) {
6557
6593
  this.force = true;
6558
6594
  }
@@ -6567,6 +6603,8 @@ var TemplateBase = class _TemplateBase {
6567
6603
  );
6568
6604
  this.baseImage = baseImage;
6569
6605
  this.baseTemplate = void 0;
6606
+ this.resetInheritedConfig();
6607
+ this.inheritImageConfig = true;
6570
6608
  if (this.forceNextLayer) {
6571
6609
  this.force = true;
6572
6610
  }
@@ -6576,6 +6614,7 @@ var TemplateBase = class _TemplateBase {
6576
6614
  fromAWSRegistry(image, credentials) {
6577
6615
  this.baseImage = image;
6578
6616
  this.baseTemplate = void 0;
6617
+ this.resetInheritedConfig();
6579
6618
  this.registryConfig = {
6580
6619
  type: "aws",
6581
6620
  awsAccessKeyId: credentials.accessKeyId,
@@ -6591,6 +6630,7 @@ var TemplateBase = class _TemplateBase {
6591
6630
  fromGCPRegistry(image, credentials) {
6592
6631
  this.baseImage = image;
6593
6632
  this.baseTemplate = void 0;
6633
+ this.resetInheritedConfig();
6594
6634
  this.registryConfig = {
6595
6635
  type: "gcp",
6596
6636
  serviceAccountJson: readGCPServiceAccountJSON(
@@ -6607,6 +6647,7 @@ var TemplateBase = class _TemplateBase {
6607
6647
  fromOCIRegistry(image, credentials) {
6608
6648
  this.baseImage = image;
6609
6649
  this.baseTemplate = void 0;
6650
+ this.resetInheritedConfig();
6610
6651
  this.registryConfig = {
6611
6652
  type: "oci",
6612
6653
  tenancyOcid: credentials.tenancyOcid,
@@ -6624,6 +6665,7 @@ var TemplateBase = class _TemplateBase {
6624
6665
  fromHuaweiCloudRegistry(image, credentials) {
6625
6666
  this.baseImage = image;
6626
6667
  this.baseTemplate = void 0;
6668
+ this.resetInheritedConfig();
6627
6669
  this.registryConfig = {
6628
6670
  type: "huawei",
6629
6671
  accessKeyId: credentials.accessKeyId,
@@ -6885,7 +6927,8 @@ var TemplateBase = class _TemplateBase {
6885
6927
  this.collectStackTrace();
6886
6928
  return this;
6887
6929
  }
6888
- setEnvs(envs) {
6930
+ setEnvs(envs, options) {
6931
+ var _a3;
6889
6932
  if (Object.keys(envs).length === 0) {
6890
6933
  return this;
6891
6934
  }
@@ -6894,7 +6937,11 @@ var TemplateBase = class _TemplateBase {
6894
6937
  args: Object.entries(envs).flatMap(([key, value]) => [key, value]),
6895
6938
  force: this.forceNextLayer
6896
6939
  });
6897
- this.envs = __spreadValues(__spreadValues({}, this.envs), envs);
6940
+ this.envDeclarations.push({
6941
+ values: __spreadValues({}, envs),
6942
+ runtime: (_a3 = options == null ? void 0 : options.runtime) != null ? _a3 : false
6943
+ });
6944
+ if (options == null ? void 0 : options.runtime) this.envs = __spreadValues(__spreadValues({}, this.envs), envs);
6898
6945
  this.collectStackTrace();
6899
6946
  return this;
6900
6947
  }
@@ -6911,7 +6958,12 @@ var TemplateBase = class _TemplateBase {
6911
6958
  * second build of the same template append a duplicate layer.
6912
6959
  */
6913
6960
  runtimeEnvInstruction() {
6914
- const { command } = envFilesCommand(this.envs);
6961
+ const { command } = envFilesCommand(
6962
+ this.envs,
6963
+ this.imageEnvs,
6964
+ this.envDeclarations,
6965
+ envSnapshotCommand(this.envDeclarations) ? BASE_ENV_PATH : void 0
6966
+ );
6915
6967
  if (command === null) {
6916
6968
  return null;
6917
6969
  }
@@ -6930,7 +6982,10 @@ var TemplateBase = class _TemplateBase {
6930
6982
  */
6931
6983
  withRuntimeEnv(instructions) {
6932
6984
  const runtimeEnv = this.runtimeEnvInstruction();
6933
- return runtimeEnv ? [...instructions, runtimeEnv] : instructions;
6985
+ if (!runtimeEnv) return instructions;
6986
+ const snapshot = envSnapshotCommand(this.envDeclarations);
6987
+ const prefix = snapshot ? [{ type: "RUN" /* RUN */, args: [snapshot, "root"], force: false }] : [];
6988
+ return [...prefix, ...instructions, runtimeEnv];
6934
6989
  }
6935
6990
  /**
6936
6991
  * Restore what the base image declares: ENV, WORKDIR and its effective command.
@@ -6955,20 +7010,32 @@ var TemplateBase = class _TemplateBase {
6955
7010
  configFailureMessage() {
6956
7011
  return `Could not read ${this.baseImage}: ${this.imageConfigError}. The template will build without the environment, working directory and start command the image declares.`;
6957
7012
  }
7013
+ resetInheritedConfig() {
7014
+ this.imageEnvs = {};
7015
+ this.imageWorkdir = void 0;
7016
+ this.imageStartCmd = void 0;
7017
+ this.imageReadyCmd = void 0;
7018
+ this.imageConfigError = void 0;
7019
+ this.imageUnusable = void 0;
7020
+ this.imageCredentials = void 0;
7021
+ this.imageDispatcher = void 0;
7022
+ this.registryConfig = void 0;
7023
+ this.inheritImageConfig = false;
7024
+ }
6958
7025
  async resolveInheritedConfig(onBuildLogs) {
6959
- var _a3;
6960
- if (this.imageOnConfigFailure === "raise" && this.imageConfigError !== void 0) {
6961
- throw new ImageConfigError(this.configFailureMessage());
6962
- }
7026
+ var _a3, _b;
6963
7027
  if (!this.inheritImageConfig || this.baseImage === void 0) {
6964
7028
  return;
6965
7029
  }
6966
- this.inheritImageConfig = false;
6967
7030
  const config = await fetchImageConfig(
6968
7031
  this.baseImage,
6969
7032
  this.imageCredentials,
6970
7033
  this.imageDispatcher === void 0 ? void 0 : { dispatcher: this.imageDispatcher }
6971
7034
  );
7035
+ this.imageEnvs = {};
7036
+ this.imageWorkdir = void 0;
7037
+ this.imageStartCmd = void 0;
7038
+ this.imageReadyCmd = void 0;
6972
7039
  if (config.error) {
6973
7040
  this.imageConfigError = config.error;
6974
7041
  this.imageUnusable = config.unusable;
@@ -6982,18 +7049,14 @@ var TemplateBase = class _TemplateBase {
6982
7049
  }
6983
7050
  return;
6984
7051
  }
6985
- this.envs = __spreadValues(__spreadValues({}, config.env), this.envs);
6986
- if (config.workdir && !this.instructions.some((i) => i.type === "WORKDIR" /* WORKDIR */)) {
6987
- this.instructions.push({
6988
- type: "WORKDIR" /* WORKDIR */,
6989
- args: [config.workdir],
6990
- force: false
6991
- });
6992
- }
7052
+ this.imageEnvs = __spreadValues({}, config.env);
7053
+ this.imageWorkdir = (_a3 = config.workdir) != null ? _a3 : void 0;
7054
+ this.imageConfigError = void 0;
7055
+ this.imageUnusable = void 0;
6993
7056
  const startCmd = effectiveStartCmd(config.entrypoint, config.cmd);
6994
7057
  if (startCmd && this.startCmd === void 0) {
6995
- this.startCmd = startCmd;
6996
- this.readyCmd = (_a3 = this.readyCmd) != null ? _a3 : waitForTimeout(2e4).getCmd();
7058
+ this.imageStartCmd = startCmd;
7059
+ this.imageReadyCmd = (_b = this.readyCmd) != null ? _b : waitForTimeout(2e4).getCmd();
6997
7060
  }
6998
7061
  }
6999
7062
  /**
@@ -7331,9 +7394,20 @@ var TemplateBase = class _TemplateBase {
7331
7394
  * @returns Template data formatted for the API
7332
7395
  */
7333
7396
  serialize(steps) {
7397
+ var _a3, _b;
7398
+ if (this.imageWorkdir) {
7399
+ steps = [
7400
+ {
7401
+ type: "WORKDIR" /* WORKDIR */,
7402
+ args: [this.imageWorkdir],
7403
+ force: false
7404
+ },
7405
+ ...steps
7406
+ ];
7407
+ }
7334
7408
  const templateData = {
7335
- startCmd: this.startCmd,
7336
- readyCmd: this.readyCmd,
7409
+ startCmd: (_a3 = this.startCmd) != null ? _a3 : this.imageStartCmd,
7410
+ readyCmd: (_b = this.readyCmd) != null ? _b : this.imageReadyCmd,
7337
7411
  preBootScript: this.patchCmd,
7338
7412
  steps,
7339
7413
  force: this.force
@@ -7929,12 +8003,12 @@ var PPIO = class {
7929
8003
  this.secret = new SecretNamespace(opts);
7930
8004
  this.codeInterpreter = new RuntimeSandboxNamespace(
7931
8005
  opts,
7932
- () => import("./sandbox-YOWIOKTV.mjs")
8006
+ () => import("./sandbox-DMY2YDSO.mjs")
7933
8007
  );
7934
8008
  this.code_interpreter = this.codeInterpreter;
7935
8009
  this.desktop = new RuntimeSandboxNamespace(
7936
8010
  opts,
7937
- () => import("./sandbox-TEFWZI7X.mjs")
8011
+ () => import("./sandbox-TS3DDCSN.mjs")
7938
8012
  );
7939
8013
  }
7940
8014
  async create(templateOrOpts, opts) {
@@ -8013,4 +8087,4 @@ export {
8013
8087
  ALL_TRAFFIC,
8014
8088
  core_default
8015
8089
  };
8016
- //# sourceMappingURL=chunk-3FDSHOTR.mjs.map
8090
+ //# sourceMappingURL=chunk-PQGBLWKQ.mjs.map