isol8 0.4.3 → 0.5.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/index.js CHANGED
@@ -146,7 +146,8 @@ var DEFAULT_CONFIG = {
146
146
  autoPrune: true,
147
147
  maxContainerAgeMs: 3600000
148
148
  },
149
- dependencies: {}
149
+ dependencies: {},
150
+ debug: false
150
151
  };
151
152
  function loadConfig(cwd) {
152
153
  const searchPaths = [
@@ -180,7 +181,8 @@ function mergeConfig(defaults, overrides) {
180
181
  dependencies: {
181
182
  ...defaults.dependencies,
182
183
  ...overrides.dependencies
183
- }
184
+ },
185
+ debug: overrides.debug ?? defaults.debug
184
186
  };
185
187
  }
186
188
  // src/engine/docker.ts
@@ -309,6 +311,29 @@ RuntimeRegistry.register(BunAdapter);
309
311
  RuntimeRegistry.register(bashAdapter);
310
312
  RuntimeRegistry.register(DenoAdapter);
311
313
 
314
+ // src/utils/logger.ts
315
+ class Logger {
316
+ debugMode = false;
317
+ setDebug(enabled) {
318
+ this.debugMode = enabled;
319
+ }
320
+ debug(...args) {
321
+ if (this.debugMode) {
322
+ console.log("[DEBUG]", ...args);
323
+ }
324
+ }
325
+ info(...args) {
326
+ console.log(...args);
327
+ }
328
+ warn(...args) {
329
+ console.warn("[WARN]", ...args);
330
+ }
331
+ error(...args) {
332
+ console.error("[ERROR]", ...args);
333
+ }
334
+ }
335
+ var logger = new Logger;
336
+
312
337
  // src/engine/concurrency.ts
313
338
  class Semaphore {
314
339
  max;
@@ -417,26 +442,32 @@ class ContainerPool {
417
442
  ...this.createOptions,
418
443
  Image: image
419
444
  });
445
+ logger.debug(`[Pool] Container ${container.id} created for image: ${image}`);
420
446
  await container.start();
447
+ logger.debug(`[Pool] Container ${container.id} started`);
421
448
  return container;
422
449
  }
423
450
  replenish(image) {
424
451
  if (this.replenishing.has(image)) {
452
+ logger.debug(`[Pool] Replenishment for ${image} already in progress`);
425
453
  return;
426
454
  }
427
455
  this.replenishing.add(image);
456
+ logger.debug(`[Pool] Starting background replenishment for image: ${image}`);
428
457
  const promise = this.createContainer(image).then((container) => {
429
458
  const pool = this.pools.get(image) ?? [];
430
459
  if (pool.length < this.poolSize) {
431
460
  pool.push({ container, createdAt: Date.now() });
432
461
  this.pools.set(image, pool);
462
+ logger.debug(`[Pool] Replenished container ${container.id} added to pool for ${image}. Pool size: ${pool.length}`);
433
463
  } else {
464
+ logger.debug(`[Pool] Replenished container ${container.id} not needed (pool for ${image} is full), destroying`);
434
465
  container.remove({ force: true }).catch((err) => {
435
- console.error(`[Pool] Error destroying unneeded replenished container ${container.id}:`, err);
466
+ logger.error(`[Pool] Error destroying unneeded replenished container ${container.id}:`, err);
436
467
  });
437
468
  }
438
469
  }).catch((err) => {
439
- console.error(`[Pool] Error during replenishment for ${image}:`, err);
470
+ logger.error(`[Pool] Error during replenishment for ${image}:`, err);
440
471
  }).finally(() => {
441
472
  this.replenishing.delete(image);
442
473
  this.pendingReplenishments.delete(promise);
@@ -635,7 +666,7 @@ function getInstallCommand(runtime, packages) {
635
666
  }
636
667
  async function installPackages(container, runtime, packages) {
637
668
  const cmd = getInstallCommand(runtime, packages);
638
- console.error(`[DEBUG] Installing packages: ${JSON.stringify(cmd)}`);
669
+ logger.debug(`Installing packages: ${JSON.stringify(cmd)}`);
639
670
  const env = [
640
671
  "PATH=/sandbox/.local/bin:/sandbox/.npm-global/bin:/sandbox/.bun-global/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
641
672
  ];
@@ -699,6 +730,7 @@ class DockerIsol8 {
699
730
  semaphore;
700
731
  sandboxSize;
701
732
  tmpSize;
733
+ persist;
702
734
  container = null;
703
735
  persistentRuntime = null;
704
736
  pool = null;
@@ -718,6 +750,10 @@ class DockerIsol8 {
718
750
  this.semaphore = new Semaphore(maxConcurrent);
719
751
  this.sandboxSize = options.sandboxSize ?? "512m";
720
752
  this.tmpSize = options.tmpSize ?? "256m";
753
+ this.persist = options.persist ?? false;
754
+ if (options.debug) {
755
+ logger.setDebug(true);
756
+ }
721
757
  }
722
758
  async start() {}
723
759
  async stop() {
@@ -825,9 +861,13 @@ class DockerIsol8 {
825
861
  const execStream = await exec.start({ Tty: false });
826
862
  yield* this.streamExecOutput(execStream, exec, container, timeoutMs);
827
863
  } finally {
828
- try {
829
- await container.remove({ force: true });
830
- } catch {}
864
+ if (this.persist) {
865
+ logger.debug(`[Persist] Leaving container running for inspection: ${container.id}`);
866
+ } else {
867
+ try {
868
+ await container.remove({ force: true });
869
+ } catch {}
870
+ }
831
871
  }
832
872
  } finally {
833
873
  this.semaphore.release();
@@ -915,7 +955,11 @@ class DockerIsol8 {
915
955
  ...req.outputPaths ? { files: await this.retrieveFiles(container, req.outputPaths) } : {}
916
956
  };
917
957
  } finally {
918
- await this.pool.release(container, image);
958
+ if (this.persist) {
959
+ logger.debug(`[Persist] Leaving container running for inspection: ${container.id}`);
960
+ } else {
961
+ await this.pool.release(container, image);
962
+ }
919
963
  }
920
964
  }
921
965
  async executePersistent(req) {
@@ -1389,7 +1433,7 @@ function createServer(options) {
1389
1433
  // package.json
1390
1434
  var package_default = {
1391
1435
  name: "isol8",
1392
- version: "0.4.2",
1436
+ version: "0.4.3",
1393
1437
  description: "Secure code execution engine for AI agents",
1394
1438
  author: "Illusion47586",
1395
1439
  license: "MIT",
@@ -1507,4 +1551,4 @@ export {
1507
1551
  BunAdapter
1508
1552
  };
1509
1553
 
1510
- //# debugId=E336C06AFE4446F964756E2164756E21
1554
+ //# debugId=BFAE8F3A0F89B57E64756E2164756E21