isol8 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -5038,23 +5038,23 @@ var require_nacl_fast = __commonJS((exports, module) => {
5038
5038
  randombytes = fn;
5039
5039
  };
5040
5040
  (function() {
5041
- var crypto = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
5042
- if (crypto && crypto.getRandomValues) {
5041
+ var crypto2 = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
5042
+ if (crypto2 && crypto2.getRandomValues) {
5043
5043
  var QUOTA = 65536;
5044
5044
  nacl.setPRNG(function(x, n) {
5045
5045
  var i, v = new Uint8Array(n);
5046
5046
  for (i = 0;i < n; i += QUOTA) {
5047
- crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
5047
+ crypto2.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
5048
5048
  }
5049
5049
  for (i = 0;i < n; i++)
5050
5050
  x[i] = v[i];
5051
5051
  cleanup(v);
5052
5052
  });
5053
5053
  } else if (true) {
5054
- crypto = __require("crypto");
5055
- if (crypto && crypto.randomBytes) {
5054
+ crypto2 = __require("crypto");
5055
+ if (crypto2 && crypto2.randomBytes) {
5056
5056
  nacl.setPRNG(function(x, n) {
5057
- var i, v = crypto.randomBytes(n);
5057
+ var i, v = crypto2.randomBytes(n);
5058
5058
  for (i = 0;i < n; i++)
5059
5059
  x[i] = v[i];
5060
5060
  cleanup(v);
@@ -6329,14 +6329,14 @@ var require_lib2 = __commonJS((exports, module) => {
6329
6329
 
6330
6330
  // node_modules/ssh2/lib/protocol/constants.js
6331
6331
  var require_constants = __commonJS((exports, module) => {
6332
- var crypto = __require("crypto");
6332
+ var crypto2 = __require("crypto");
6333
6333
  var cpuInfo;
6334
6334
  try {
6335
6335
  cpuInfo = require_lib2()();
6336
6336
  } catch {}
6337
6337
  var { bindingAvailable, CIPHER_INFO, MAC_INFO } = require_crypto();
6338
6338
  var eddsaSupported = (() => {
6339
- if (typeof crypto.sign === "function" && typeof crypto.verify === "function") {
6339
+ if (typeof crypto2.sign === "function" && typeof crypto2.verify === "function") {
6340
6340
  const key = `-----BEGIN PRIVATE KEY-----\r
6341
6341
  MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD` + `/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
6342
6342
  -----END PRIVATE KEY-----`;
@@ -6344,14 +6344,14 @@ MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD` + `/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
6344
6344
  let sig;
6345
6345
  let verified;
6346
6346
  try {
6347
- sig = crypto.sign(null, data, key);
6348
- verified = crypto.verify(null, data, key, sig);
6347
+ sig = crypto2.sign(null, data, key);
6348
+ verified = crypto2.verify(null, data, key, sig);
6349
6349
  } catch {}
6350
6350
  return Buffer.isBuffer(sig) && sig.length === 64 && verified === true;
6351
6351
  }
6352
6352
  return false;
6353
6353
  })();
6354
- var curve25519Supported = typeof crypto.diffieHellman === "function" && typeof crypto.generateKeyPairSync === "function" && typeof crypto.createPublicKey === "function";
6354
+ var curve25519Supported = typeof crypto2.diffieHellman === "function" && typeof crypto2.generateKeyPairSync === "function" && typeof crypto2.createPublicKey === "function";
6355
6355
  var DEFAULT_KEX = [
6356
6356
  "ecdh-sha2-nistp256",
6357
6357
  "ecdh-sha2-nistp384",
@@ -6386,7 +6386,7 @@ MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD` + `/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
6386
6386
  "ssh-dss"
6387
6387
  ]);
6388
6388
  var canUseCipher = (() => {
6389
- const ciphers = crypto.getCiphers();
6389
+ const ciphers = crypto2.getCiphers();
6390
6390
  return (name) => ciphers.includes(CIPHER_INFO[name].sslName);
6391
6391
  })();
6392
6392
  var DEFAULT_CIPHER = [
@@ -6421,7 +6421,7 @@ MC4CAQAwBQYDK2VwBCIEIHKj+sVa9WcD` + `/q2DJUJaf43Kptc8xYuUQA4bOFj9vC8T\r
6421
6421
  "arcfour"
6422
6422
  ].filter(canUseCipher));
6423
6423
  var canUseMAC = (() => {
6424
- const hashes = crypto.getHashes();
6424
+ const hashes = crypto2.getHashes();
6425
6425
  return (name) => hashes.includes(MAC_INFO[name].sslName);
6426
6426
  })();
6427
6427
  var DEFAULT_MAC = [
@@ -54803,6 +54803,10 @@ function mergeConfig(defaults, overrides) {
54803
54803
  seccomp: overrides.security?.seccomp ?? defaults.security.seccomp,
54804
54804
  customProfilePath: overrides.security?.customProfilePath ?? defaults.security.customProfilePath
54805
54805
  },
54806
+ audit: {
54807
+ ...defaults.audit,
54808
+ ...overrides.audit
54809
+ },
54806
54810
  debug: overrides.debug ?? defaults.debug
54807
54811
  };
54808
54812
  }
@@ -54830,6 +54834,16 @@ var init_config = __esm(() => {
54830
54834
  security: {
54831
54835
  seccomp: "strict"
54832
54836
  },
54837
+ audit: {
54838
+ enabled: false,
54839
+ destination: "filesystem",
54840
+ logDir: undefined,
54841
+ postLogScript: undefined,
54842
+ trackResources: true,
54843
+ retentionDays: 90,
54844
+ includeCode: false,
54845
+ includeOutput: false
54846
+ },
54833
54847
  debug: false
54834
54848
  };
54835
54849
  });
@@ -55022,6 +55036,144 @@ var init_logger = __esm(() => {
55022
55036
  logger = new Logger;
55023
55037
  });
55024
55038
 
55039
+ // src/engine/audit.ts
55040
+ import { spawn } from "node:child_process";
55041
+ import { appendFileSync, existsSync as existsSync2, mkdirSync, readdirSync, statSync, unlinkSync } from "node:fs";
55042
+ import { join as join2 } from "node:path";
55043
+
55044
+ class AuditLogger {
55045
+ config;
55046
+ auditFile;
55047
+ constructor(config) {
55048
+ this.config = config;
55049
+ const auditDir = config.logDir ?? process.env.ISOL8_AUDIT_DIR ?? join2(process.cwd(), "./.isol8_audit");
55050
+ this.auditFile = join2(auditDir, "executions.log");
55051
+ if (!existsSync2(auditDir)) {
55052
+ try {
55053
+ mkdirSync(auditDir, { recursive: true });
55054
+ } catch (err) {
55055
+ logger.error("Failed to create audit dir:", err);
55056
+ }
55057
+ }
55058
+ this.cleanupOldLogs();
55059
+ }
55060
+ cleanupOldLogs() {
55061
+ if (!this.config.enabled || this.config.retentionDays <= 0) {
55062
+ return;
55063
+ }
55064
+ try {
55065
+ const auditDir = join2(this.auditFile, "..");
55066
+ if (!existsSync2(auditDir)) {
55067
+ return;
55068
+ }
55069
+ const cutoffTime = Date.now() - this.config.retentionDays * 24 * 60 * 60 * 1000;
55070
+ const files = readdirSync(auditDir);
55071
+ let cleanedCount = 0;
55072
+ for (const file of files) {
55073
+ if (file.endsWith(".log") || file.endsWith(".jsonl")) {
55074
+ const filePath = join2(auditDir, file);
55075
+ try {
55076
+ const stats = statSync(filePath);
55077
+ if (stats.mtimeMs < cutoffTime) {
55078
+ unlinkSync(filePath);
55079
+ cleanedCount++;
55080
+ logger.debug(`Cleaned up old audit log: ${file}`);
55081
+ }
55082
+ } catch (err) {
55083
+ logger.debug(`Failed to check/remove old log file ${file}:`, err);
55084
+ }
55085
+ }
55086
+ }
55087
+ if (cleanedCount > 0) {
55088
+ logger.info(`Audit log cleanup: removed ${cleanedCount} old log files`);
55089
+ }
55090
+ } catch (err) {
55091
+ logger.error("Failed to cleanup old audit logs:", err);
55092
+ }
55093
+ }
55094
+ record(audit) {
55095
+ if (!this.config.enabled) {
55096
+ return;
55097
+ }
55098
+ try {
55099
+ const filteredAudit = this.filterAuditData(audit);
55100
+ const line = `${JSON.stringify(filteredAudit)}
55101
+ `;
55102
+ switch (this.config.destination) {
55103
+ case "file":
55104
+ case "filesystem":
55105
+ appendFileSync(this.auditFile, line, { encoding: "utf-8" });
55106
+ break;
55107
+ case "stdout":
55108
+ console.log("AUDIT_LOG:", filteredAudit);
55109
+ break;
55110
+ default:
55111
+ logger.error(`Unsupported audit destination: ${this.config.destination}`);
55112
+ return;
55113
+ }
55114
+ logger.debug("Audit record written:", audit.executionId);
55115
+ if (this.config.postLogScript) {
55116
+ this.runPostLogScript();
55117
+ }
55118
+ } catch (err) {
55119
+ logger.error("Failed to write audit record:", err);
55120
+ }
55121
+ }
55122
+ runPostLogScript() {
55123
+ if (!this.config.postLogScript) {
55124
+ return;
55125
+ }
55126
+ try {
55127
+ const child = spawn(this.config.postLogScript, [this.auditFile], {
55128
+ detached: true,
55129
+ stdio: "ignore"
55130
+ });
55131
+ child.on("error", (err) => {
55132
+ logger.error("Failed to run post-log script:", err);
55133
+ });
55134
+ child.unref();
55135
+ } catch (err) {
55136
+ logger.error("Failed to spawn post-log script:", err);
55137
+ }
55138
+ }
55139
+ filterAuditData(audit) {
55140
+ const result = {
55141
+ executionId: audit.executionId,
55142
+ userId: audit.userId,
55143
+ timestamp: audit.timestamp,
55144
+ runtime: audit.runtime,
55145
+ codeHash: audit.codeHash,
55146
+ containerId: audit.containerId,
55147
+ exitCode: audit.exitCode,
55148
+ durationMs: audit.durationMs
55149
+ };
55150
+ if (audit.resourceUsage !== undefined) {
55151
+ result.resourceUsage = audit.resourceUsage;
55152
+ }
55153
+ if (audit.securityEvents !== undefined) {
55154
+ result.securityEvents = audit.securityEvents;
55155
+ }
55156
+ if (audit.metadata !== undefined) {
55157
+ result.metadata = audit.metadata;
55158
+ }
55159
+ if (this.config.includeCode && audit.code !== undefined) {
55160
+ result.code = audit.code;
55161
+ }
55162
+ if (this.config.includeOutput) {
55163
+ if (audit.stdout !== undefined) {
55164
+ result.stdout = audit.stdout;
55165
+ }
55166
+ if (audit.stderr !== undefined) {
55167
+ result.stderr = audit.stderr;
55168
+ }
55169
+ }
55170
+ return result;
55171
+ }
55172
+ }
55173
+ var init_audit = __esm(() => {
55174
+ init_logger();
55175
+ });
55176
+
55025
55177
  // src/engine/concurrency.ts
55026
55178
  class Semaphore {
55027
55179
  max;
@@ -55180,9 +55332,55 @@ var init_pool = __esm(() => {
55180
55332
  init_logger();
55181
55333
  });
55182
55334
 
55335
+ // src/engine/stats.ts
55336
+ function calculateCPUPercent(stats) {
55337
+ const cpuDelta = stats.cpu_stats.cpu_usage.total_usage - stats.precpu_stats.cpu_usage.total_usage;
55338
+ const systemDelta = stats.cpu_stats.system_cpu_usage - stats.precpu_stats.system_cpu_usage;
55339
+ if (systemDelta === 0 || cpuDelta === 0) {
55340
+ return 0;
55341
+ }
55342
+ const numCores = stats.cpu_stats.online_cpus ?? stats.cpu_stats.cpu_usage.percpu_usage?.length ?? 1;
55343
+ return cpuDelta / systemDelta * numCores * 100;
55344
+ }
55345
+ function calculateNetworkStats(stats) {
55346
+ if (!stats.networks) {
55347
+ return { in: 0, out: 0 };
55348
+ }
55349
+ let rxBytes = 0;
55350
+ let txBytes = 0;
55351
+ for (const iface of Object.values(stats.networks)) {
55352
+ rxBytes += iface.rx_bytes;
55353
+ txBytes += iface.tx_bytes;
55354
+ }
55355
+ return { in: rxBytes, out: txBytes };
55356
+ }
55357
+ async function getContainerStats(container) {
55358
+ const stats = await container.stats({
55359
+ stream: false
55360
+ });
55361
+ const cpuPercent = calculateCPUPercent(stats);
55362
+ const memoryBytes = stats.memory_stats.usage;
55363
+ const network = calculateNetworkStats(stats);
55364
+ return {
55365
+ cpuPercent: Math.round(cpuPercent * 100) / 100,
55366
+ memoryMB: Math.round(memoryBytes / (1024 * 1024)),
55367
+ networkBytesIn: network.in,
55368
+ networkBytesOut: network.out
55369
+ };
55370
+ }
55371
+ function calculateResourceDelta(before, after) {
55372
+ return {
55373
+ cpuPercent: after.cpuPercent,
55374
+ memoryMB: after.memoryMB,
55375
+ networkBytesIn: after.networkBytesIn - before.networkBytesIn,
55376
+ networkBytesOut: after.networkBytesOut - before.networkBytesOut
55377
+ };
55378
+ }
55379
+
55183
55380
  // src/engine/utils.ts
55184
55381
  var exports_utils = {};
55185
55382
  __export(exports_utils, {
55383
+ validatePackageName: () => validatePackageName,
55186
55384
  truncateOutput: () => truncateOutput,
55187
55385
  parseMemoryLimit: () => parseMemoryLimit,
55188
55386
  maskSecrets: () => maskSecrets,
@@ -55277,20 +55475,26 @@ function extractFromTar(tarBuffer, targetPath) {
55277
55475
  }
55278
55476
  throw new Error(`File "${targetPath}" not found in tar archive`);
55279
55477
  }
55478
+ function validatePackageName(name) {
55479
+ if (!/^[@a-zA-Z0-9_./\-=]+$/.test(name)) {
55480
+ throw new Error(`Invalid package name: "${name}". Only alphanumeric, -, _, ., /, @, and = are allowed.`);
55481
+ }
55482
+ return name;
55483
+ }
55280
55484
 
55281
55485
  // src/engine/docker.ts
55282
55486
  var exports_docker = {};
55283
55487
  __export(exports_docker, {
55284
55488
  DockerIsol8: () => DockerIsol8
55285
55489
  });
55286
- import { spawn } from "node:child_process";
55490
+ import { spawn as spawn2 } from "node:child_process";
55287
55491
  import { randomUUID } from "node:crypto";
55288
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
55492
+ import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
55289
55493
  import { PassThrough } from "node:stream";
55290
55494
  async function writeFileViaExec(container, filePath, content) {
55291
55495
  const data = typeof content === "string" ? Buffer.from(content, "utf-8") : content;
55292
55496
  return new Promise((resolve2, reject) => {
55293
- const child = spawn("docker", ["exec", "-i", "-u", "sandbox", container.id, "sh", "-c", `cat > ${filePath}`], {
55497
+ const child = spawn2("docker", ["exec", "-i", "-u", "sandbox", container.id, "sh", "-c", `cat > ${filePath}`], {
55294
55498
  stdio: ["pipe", "ignore", "pipe"]
55295
55499
  });
55296
55500
  child.on("error", (err) => {
@@ -55476,6 +55680,7 @@ class DockerIsol8 {
55476
55680
  tmpSize;
55477
55681
  security;
55478
55682
  persist;
55683
+ auditLogger;
55479
55684
  container = null;
55480
55685
  persistentRuntime = null;
55481
55686
  pool = null;
@@ -55497,6 +55702,9 @@ class DockerIsol8 {
55497
55702
  this.tmpSize = options.tmpSize ?? "256m";
55498
55703
  this.persist = options.persist ?? false;
55499
55704
  this.security = options.security ?? { seccomp: "strict" };
55705
+ if (options.audit) {
55706
+ this.auditLogger = new AuditLogger(options.audit);
55707
+ }
55500
55708
  if (options.debug) {
55501
55709
  logger.setDebug(true);
55502
55710
  }
@@ -55520,12 +55728,79 @@ class DockerIsol8 {
55520
55728
  }
55521
55729
  async execute(req) {
55522
55730
  await this.semaphore.acquire();
55731
+ const startTime = Date.now();
55523
55732
  try {
55524
- return this.mode === "persistent" ? await this.executePersistent(req) : await this.executeEphemeral(req);
55733
+ const result = this.mode === "persistent" ? await this.executePersistent(req, startTime) : await this.executeEphemeral(req, startTime);
55734
+ return result;
55525
55735
  } finally {
55526
55736
  this.semaphore.release();
55527
55737
  }
55528
55738
  }
55739
+ async recordAudit(req, result, startTime, container) {
55740
+ try {
55741
+ const enc = new TextEncoder;
55742
+ const data = enc.encode(req.code);
55743
+ const digest = await crypto.subtle.digest("SHA-256", data);
55744
+ const codeHash = Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
55745
+ let securityEvents;
55746
+ if (container && this.network === "filtered") {
55747
+ securityEvents = await this.collectSecurityEvents(container);
55748
+ if (securityEvents.length === 0) {
55749
+ securityEvents = undefined;
55750
+ }
55751
+ }
55752
+ const audit = {
55753
+ executionId: result.executionId,
55754
+ userId: req.metadata?.userId || "",
55755
+ timestamp: new Date(startTime).toISOString(),
55756
+ runtime: result.runtime,
55757
+ codeHash,
55758
+ containerId: result.containerId || "",
55759
+ exitCode: result.exitCode,
55760
+ durationMs: result.durationMs,
55761
+ resourceUsage: result.resourceUsage,
55762
+ securityEvents,
55763
+ metadata: req.metadata
55764
+ };
55765
+ this.auditLogger.record(audit);
55766
+ } catch (err) {
55767
+ logger.error("Failed to record audit log:", err);
55768
+ }
55769
+ }
55770
+ async collectSecurityEvents(container) {
55771
+ const events = [];
55772
+ try {
55773
+ const exec = await container.exec({
55774
+ Cmd: ["cat", "/tmp/isol8-proxy/security-events.jsonl"],
55775
+ AttachStdout: true,
55776
+ AttachStderr: false,
55777
+ User: "root"
55778
+ });
55779
+ const stream = await exec.start({ Tty: false });
55780
+ const chunks = [];
55781
+ for await (const chunk of stream) {
55782
+ chunks.push(chunk);
55783
+ }
55784
+ const output = Buffer.concat(chunks).toString("utf-8").trim();
55785
+ if (output) {
55786
+ for (const line of output.split(`
55787
+ `)) {
55788
+ if (line.trim()) {
55789
+ try {
55790
+ const event = JSON.parse(line);
55791
+ events.push({
55792
+ type: event.type || "unknown",
55793
+ message: `Security event: ${event.type}`,
55794
+ details: event.details || {},
55795
+ timestamp: event.timestamp || new Date().toISOString()
55796
+ });
55797
+ } catch {}
55798
+ }
55799
+ }
55800
+ }
55801
+ } catch {}
55802
+ return events;
55803
+ }
55529
55804
  async putFile(path, content) {
55530
55805
  if (!this.container) {
55531
55806
  throw new Error("No active container. Call execute() first in persistent mode.");
@@ -55633,7 +55908,7 @@ class DockerIsol8 {
55633
55908
  return adapter.image;
55634
55909
  }
55635
55910
  }
55636
- async executeEphemeral(req) {
55911
+ async executeEphemeral(req, startTime) {
55637
55912
  const adapter = this.getAdapter(req.runtime);
55638
55913
  const timeoutMs = req.timeoutMs ?? this.defaultTimeoutMs;
55639
55914
  const image = await this.resolveImage(adapter);
@@ -55652,6 +55927,14 @@ class DockerIsol8 {
55652
55927
  });
55653
55928
  }
55654
55929
  const container = await this.pool.acquire(image);
55930
+ let startStats;
55931
+ if (this.auditLogger) {
55932
+ try {
55933
+ startStats = await getContainerStats(container);
55934
+ } catch (err) {
55935
+ logger.debug("Failed to collect baseline stats:", err);
55936
+ }
55937
+ }
55655
55938
  try {
55656
55939
  if (this.network === "filtered") {
55657
55940
  await startProxy(container, this.networkFilter);
@@ -55692,7 +55975,16 @@ class DockerIsol8 {
55692
55975
  const { stdout, stderr, truncated } = await this.collectExecOutput(execStream, container, timeoutMs);
55693
55976
  const durationMs = Math.round(performance.now() - start);
55694
55977
  const inspectResult = await exec.inspect();
55695
- return {
55978
+ let resourceUsage;
55979
+ if (startStats) {
55980
+ try {
55981
+ const endStats = await getContainerStats(container);
55982
+ resourceUsage = calculateResourceDelta(startStats, endStats);
55983
+ } catch (err) {
55984
+ logger.debug("Failed to collect final stats:", err);
55985
+ }
55986
+ }
55987
+ const result = {
55696
55988
  stdout: this.postProcessOutput(stdout, truncated),
55697
55989
  stderr: this.postProcessOutput(stderr, false),
55698
55990
  exitCode: inspectResult.ExitCode ?? 1,
@@ -55702,8 +55994,13 @@ class DockerIsol8 {
55702
55994
  runtime: req.runtime,
55703
55995
  timestamp: new Date().toISOString(),
55704
55996
  containerId: container.id,
55997
+ ...resourceUsage ? { resourceUsage } : {},
55705
55998
  ...req.outputPaths ? { files: await this.retrieveFiles(container, req.outputPaths) } : {}
55706
55999
  };
56000
+ if (this.auditLogger) {
56001
+ await this.recordAudit(req, result, startTime, container);
56002
+ }
56003
+ return result;
55707
56004
  } finally {
55708
56005
  if (this.persist) {
55709
56006
  logger.debug(`[Persist] Leaving container running for inspection: ${container.id}`);
@@ -55712,7 +56009,7 @@ class DockerIsol8 {
55712
56009
  }
55713
56010
  }
55714
56011
  }
55715
- async executePersistent(req) {
56012
+ async executePersistent(req, startTime) {
55716
56013
  const adapter = this.getAdapter(req.runtime);
55717
56014
  const timeoutMs = req.timeoutMs ?? this.defaultTimeoutMs;
55718
56015
  if (!this.container) {
@@ -55766,7 +56063,21 @@ class DockerIsol8 {
55766
56063
  const { stdout, stderr, truncated } = await this.collectExecOutput(execStream, this.container, timeoutMs);
55767
56064
  const durationMs = Math.round(performance.now() - start);
55768
56065
  const inspectResult = await exec.inspect();
55769
- return {
56066
+ let resourceUsage;
56067
+ if (this.auditLogger) {
56068
+ try {
56069
+ const endStats = await getContainerStats(this.container);
56070
+ resourceUsage = {
56071
+ cpuPercent: endStats.cpuPercent,
56072
+ memoryMB: endStats.memoryMB,
56073
+ networkBytesIn: endStats.networkBytesIn,
56074
+ networkBytesOut: endStats.networkBytesOut
56075
+ };
56076
+ } catch (err) {
56077
+ logger.debug("Failed to collect resource stats:", err);
56078
+ }
56079
+ }
56080
+ const result = {
55770
56081
  stdout: this.postProcessOutput(stdout, truncated),
55771
56082
  stderr: this.postProcessOutput(stderr, false),
55772
56083
  exitCode: inspectResult.ExitCode ?? 1,
@@ -55776,8 +56087,13 @@ class DockerIsol8 {
55776
56087
  runtime: req.runtime,
55777
56088
  timestamp: new Date().toISOString(),
55778
56089
  containerId: this.container?.id,
56090
+ ...resourceUsage ? { resourceUsage } : {},
55779
56091
  ...req.outputPaths ? { files: await this.retrieveFiles(this.container, req.outputPaths) } : {}
55780
56092
  };
56093
+ if (this.auditLogger) {
56094
+ await this.recordAudit(req, result, startTime, this.container);
56095
+ }
56096
+ return result;
55781
56097
  }
55782
56098
  async retrieveFiles(container, paths) {
55783
56099
  const files = {};
@@ -55869,11 +56185,11 @@ class DockerIsol8 {
55869
56185
  }
55870
56186
  loadDefaultSeccompProfile() {
55871
56187
  const devPath = new URL("../../docker/seccomp-profile.json", import.meta.url);
55872
- if (existsSync2(devPath)) {
56188
+ if (existsSync3(devPath)) {
55873
56189
  return readFileSync2(devPath, "utf-8");
55874
56190
  }
55875
56191
  const prodPath = new URL("./docker/seccomp-profile.json", import.meta.url);
55876
- if (existsSync2(prodPath)) {
56192
+ if (existsSync3(prodPath)) {
55877
56193
  return readFileSync2(prodPath, "utf-8");
55878
56194
  }
55879
56195
  logger.warn("Could not locate default seccomp profile. Running without seccomp filter.");
@@ -56079,6 +56395,7 @@ var import_dockerode, SANDBOX_WORKDIR = "/sandbox", MAX_OUTPUT_BYTES, PROXY_PORT
56079
56395
  var init_docker = __esm(() => {
56080
56396
  init_runtime();
56081
56397
  init_logger();
56398
+ init_audit();
56082
56399
  init_pool();
56083
56400
  import_dockerode = __toESM(require_docker(), 1);
56084
56401
  MAX_OUTPUT_BYTES = 1024 * 1024;
@@ -56089,7 +56406,7 @@ var package_default;
56089
56406
  var init_package = __esm(() => {
56090
56407
  package_default = {
56091
56408
  name: "isol8",
56092
- version: "0.8.1",
56409
+ version: "0.8.3",
56093
56410
  description: "Secure code execution engine for AI agents",
56094
56411
  author: "Illusion47586",
56095
56412
  license: "MIT",
@@ -57847,7 +58164,8 @@ async function createServer(options) {
57847
58164
  sandboxSize: config.defaults.sandboxSize,
57848
58165
  tmpSize: config.defaults.tmpSize,
57849
58166
  ...body.options,
57850
- mode: body.sessionId ? "persistent" : "ephemeral"
58167
+ mode: body.sessionId ? "persistent" : "ephemeral",
58168
+ audit: config.audit
57851
58169
  };
57852
58170
  let engine;
57853
58171
  if (body.sessionId) {
@@ -58018,15 +58336,15 @@ var init_server = __esm(() => {
58018
58336
  // src/cli.ts
58019
58337
  import {
58020
58338
  chmodSync,
58021
- existsSync as existsSync4,
58022
- mkdirSync,
58339
+ existsSync as existsSync5,
58340
+ mkdirSync as mkdirSync2,
58023
58341
  readFileSync as readFileSync3,
58024
58342
  renameSync,
58025
- unlinkSync,
58343
+ unlinkSync as unlinkSync2,
58026
58344
  writeFileSync
58027
58345
  } from "node:fs";
58028
58346
  import { arch, homedir as homedir2, platform } from "node:os";
58029
- import { join as join2, resolve as resolve2 } from "node:path";
58347
+ import { join as join3, resolve as resolve2 } from "node:path";
58030
58348
 
58031
58349
  // node_modules/commander/esm.mjs
58032
58350
  var import__ = __toESM(require_commander(), 1);
@@ -61420,10 +61738,10 @@ init_docker();
61420
61738
 
61421
61739
  // src/engine/image-builder.ts
61422
61740
  init_runtime();
61423
- import { existsSync as existsSync3 } from "node:fs";
61741
+ import { existsSync as existsSync4 } from "node:fs";
61424
61742
  function resolveDockerDir() {
61425
61743
  const fromBundled = new URL("../docker", import.meta.url).pathname;
61426
- if (existsSync3(fromBundled)) {
61744
+ if (existsSync4(fromBundled)) {
61427
61745
  return fromBundled;
61428
61746
  }
61429
61747
  return new URL("../../docker", import.meta.url).pathname;
@@ -61502,8 +61820,9 @@ async function buildCustomImage(docker, runtime, packages, onProgress) {
61502
61820
  const dockerfileContent = `FROM isol8:${runtime}
61503
61821
  ${installCmd}
61504
61822
  `;
61505
- const { createTarBuffer: createTarBuffer2 } = await Promise.resolve().then(() => exports_utils);
61823
+ const { createTarBuffer: createTarBuffer2, validatePackageName: validatePackageName2 } = await Promise.resolve().then(() => exports_utils);
61506
61824
  const { Readable } = await import("node:stream");
61825
+ packages.forEach(validatePackageName2);
61507
61826
  const tarBuffer = createTarBuffer2("Dockerfile", dockerfileContent);
61508
61827
  const stream = await docker.buildImage(Readable.from(tarBuffer), {
61509
61828
  t: tag,
@@ -61775,7 +62094,7 @@ function getServerBinaryName() {
61775
62094
  return `isol8-server-${resolvedOs}-${resolvedArch}`;
61776
62095
  }
61777
62096
  async function getServerBinaryVersion(binaryPath) {
61778
- if (!existsSync4(binaryPath)) {
62097
+ if (!existsSync5(binaryPath)) {
61779
62098
  logger.debug(`[Serve] No binary found at ${binaryPath}`);
61780
62099
  return null;
61781
62100
  }
@@ -61808,8 +62127,8 @@ async function downloadServerBinary(binaryPath) {
61808
62127
  }
61809
62128
  process.exit(1);
61810
62129
  }
61811
- const binDir = join2(homedir2(), ".isol8", "bin");
61812
- mkdirSync(binDir, { recursive: true });
62130
+ const binDir = join3(homedir2(), ".isol8", "bin");
62131
+ mkdirSync2(binDir, { recursive: true });
61813
62132
  const tmpPath = `${binaryPath}.tmp`;
61814
62133
  const buffer = Buffer.from(await response.arrayBuffer());
61815
62134
  writeFileSync(tmpPath, buffer);
@@ -61820,8 +62139,8 @@ async function downloadServerBinary(binaryPath) {
61820
62139
  } catch (err) {
61821
62140
  spinner.fail("Failed to download server binary");
61822
62141
  const tmpPath = `${binaryPath}.tmp`;
61823
- if (existsSync4(tmpPath)) {
61824
- unlinkSync(tmpPath);
62142
+ if (existsSync5(tmpPath)) {
62143
+ unlinkSync2(tmpPath);
61825
62144
  }
61826
62145
  throw err;
61827
62146
  }
@@ -61840,8 +62159,8 @@ async function promptYesNo(question) {
61840
62159
  return normalized === "" || normalized === "y" || normalized === "yes";
61841
62160
  }
61842
62161
  async function ensureServerBinary(forceUpdate) {
61843
- const binDir = join2(homedir2(), ".isol8", "bin");
61844
- const binaryPath = join2(binDir, "isol8-server");
62162
+ const binDir = join3(homedir2(), ".isol8", "bin");
62163
+ const binaryPath = join3(binDir, "isol8-server");
61845
62164
  logger.debug(`[Serve] Binary path: ${binaryPath}, forceUpdate: ${forceUpdate}`);
61846
62165
  if (forceUpdate) {
61847
62166
  logger.debug("[Serve] Force update requested");
@@ -61871,10 +62190,10 @@ async function ensureServerBinary(forceUpdate) {
61871
62190
  program2.command("config").description("Show the resolved isol8 configuration").option("--json", "Output as raw JSON").action((opts) => {
61872
62191
  const config = loadConfig();
61873
62192
  const searchPaths = [
61874
- join2(resolve2(process.cwd()), "isol8.config.json"),
61875
- join2(homedir2(), ".isol8", "config.json")
62193
+ join3(resolve2(process.cwd()), "isol8.config.json"),
62194
+ join3(homedir2(), ".isol8", "config.json")
61876
62195
  ];
61877
- const loadedFrom = searchPaths.find((p) => existsSync4(p));
62196
+ const loadedFrom = searchPaths.find((p) => existsSync5(p));
61878
62197
  logger.debug(`[Config] Config source: ${loadedFrom ?? "defaults"}`);
61879
62198
  logger.debug(`[Config] Resolved config: ${JSON.stringify(config)}`);
61880
62199
  if (opts.json) {
@@ -62009,7 +62328,7 @@ async function resolveRunInput(file, opts) {
62009
62328
  } else if (file) {
62010
62329
  const filePath = resolve2(file);
62011
62330
  logger.debug(`[Run] Reading file: ${filePath}`);
62012
- if (!existsSync4(filePath)) {
62331
+ if (!existsSync5(filePath)) {
62013
62332
  console.error(`[ERR] File not found: ${file}`);
62014
62333
  process.exit(1);
62015
62334
  }
@@ -62096,4 +62415,4 @@ if (!process.argv.slice(2).length) {
62096
62415
  }
62097
62416
  program2.parse();
62098
62417
 
62099
- //# debugId=2B71A68DA2ABDB9664756E2164756E21
62418
+ //# debugId=618F453F99998F9064756E2164756E21