isol8 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -101,6 +101,7 @@ isol8 run script.py --host http://server:3000 --key my-api-key
101
101
  | `--allow <regex>` | Whitelist regex (repeatable, for `filtered`) | — |
102
102
  | `--deny <regex>` | Blacklist regex (repeatable, for `filtered`) | — |
103
103
  | `--out <file>` | Write stdout to file | — |
104
+ | `--stream` | Stream output in real-time | `false` |
104
105
  | `--persistent` | Keep container alive between runs | `false` |
105
106
  | `--timeout <ms>` | Execution timeout in milliseconds | `30000` |
106
107
  | `--memory <limit>` | Memory limit (e.g. `512m`, `1g`) | `512m` |
package/dist/cli.js CHANGED
@@ -6929,6 +6929,11 @@ var require_utils2 = __commonJS((exports, module) => {
6929
6929
  };
6930
6930
  });
6931
6931
 
6932
+ // node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node
6933
+ var require_sshcrypto = __commonJS((exports, module) => {
6934
+ module.exports = __require("./sshcrypto-0209sx47.node");
6935
+ });
6936
+
6932
6937
  // node_modules/ssh2/lib/protocol/crypto/poly1305.js
6933
6938
  var require_poly1305 = __commonJS((exports, module) => {
6934
6939
  var __dirname = "/home/runner/work/isol8/isol8/node_modules/ssh2/lib/protocol/crypto", __filename = "/home/runner/work/isol8/isol8/node_modules/ssh2/lib/protocol/crypto/poly1305.js";
@@ -7415,7 +7420,7 @@ var require_crypto = __commonJS((exports, module) => {
7415
7420
  var ChaChaPolyDecipher;
7416
7421
  var GenericDecipher;
7417
7422
  try {
7418
- binding = (()=>{throw new Error("Cannot require module "+"./crypto/build/Release/sshcrypto.node");})();
7423
+ binding = require_sshcrypto();
7419
7424
  ({
7420
7425
  AESGCMCipher,
7421
7426
  ChaChaPolyCipher,
@@ -55013,6 +55018,7 @@ class ContainerPool {
55013
55018
  createOptions;
55014
55019
  pools = new Map;
55015
55020
  replenishing = new Set;
55021
+ pendingReplenishments = new Set;
55016
55022
  constructor(options) {
55017
55023
  this.docker = options.docker;
55018
55024
  this.poolSize = options.poolSize ?? 2;
@@ -55062,6 +55068,7 @@ class ContainerPool {
55062
55068
  await Promise.all(promises);
55063
55069
  }
55064
55070
  async drain() {
55071
+ await Promise.all(this.pendingReplenishments);
55065
55072
  const promises = [];
55066
55073
  for (const [, pool] of this.pools) {
55067
55074
  for (const entry of pool) {
@@ -55076,26 +55083,20 @@ class ContainerPool {
55076
55083
  ...this.createOptions,
55077
55084
  Image: image
55078
55085
  });
55079
- console.log(`[Pool] Container ${container.id} created for image: ${image}`);
55080
55086
  await container.start();
55081
- console.log(`[Pool] Container ${container.id} started.`);
55082
55087
  return container;
55083
55088
  }
55084
55089
  replenish(image) {
55085
55090
  if (this.replenishing.has(image)) {
55086
- console.log(`[Pool] Replenishment for ${image} already in progress.`);
55087
55091
  return;
55088
55092
  }
55089
55093
  this.replenishing.add(image);
55090
- console.log(`[Pool] Starting background replenishment for image: ${image}`);
55091
- this.createContainer(image).then((container) => {
55094
+ const promise = this.createContainer(image).then((container) => {
55092
55095
  const pool = this.pools.get(image) ?? [];
55093
55096
  if (pool.length < this.poolSize) {
55094
55097
  pool.push({ container, createdAt: Date.now() });
55095
55098
  this.pools.set(image, pool);
55096
- console.log(`[Pool] Replenished container ${container.id} added to pool for ${image}. Current pool size: ${pool.length}`);
55097
55099
  } else {
55098
- console.log(`[Pool] Replenished container ${container.id} not needed (pool for ${image} is full), destroying.`);
55099
55100
  container.remove({ force: true }).catch((err) => {
55100
55101
  console.error(`[Pool] Error destroying unneeded replenished container ${container.id}:`, err);
55101
55102
  });
@@ -55104,7 +55105,9 @@ class ContainerPool {
55104
55105
  console.error(`[Pool] Error during replenishment for ${image}:`, err);
55105
55106
  }).finally(() => {
55106
55107
  this.replenishing.delete(image);
55108
+ this.pendingReplenishments.delete(promise);
55107
55109
  });
55110
+ this.pendingReplenishments.add(promise);
55108
55111
  }
55109
55112
  }
55110
55113
 
@@ -61218,7 +61221,7 @@ program2.command("setup").description("Check Docker and build isol8 images").opt
61218
61221
  console.log(`
61219
61222
  [DONE] Setup complete!`);
61220
61223
  });
61221
- program2.command("run").description("Execute code in isol8").argument("[file]", "Script file to execute").option("-e, --eval <code>", "Execute inline code string").option("-r, --runtime <name>", "Force runtime (python, node, bun, deno, bash)").option("--net <mode>", "Network mode: none, host, filtered", "none").option("--allow <regex>", "Whitelist regex for filtered mode (repeatable)", collect, []).option("--deny <regex>", "Blacklist regex for filtered mode (repeatable)", collect, []).option("--out <file>", "Write output to file").option("--persistent", "Use persistent container").option("--timeout <ms>", "Execution timeout in milliseconds").option("--memory <limit>", "Memory limit (e.g. 512m, 1g)").option("--cpu <limit>", "CPU limit as fraction (e.g. 0.5, 2.0)").option("--image <name>", "Override Docker image").option("--pids-limit <n>", "Maximum number of processes").option("--writable", "Disable read-only root filesystem").option("--max-output <bytes>", "Maximum output size in bytes").option("--secret <KEY=VALUE>", "Secret env var (repeatable, values masked)", collect, []).option("--sandbox-size <size>", "Sandbox tmpfs size (e.g. 128m)").option("--tmp-size <size>", "Tmp tmpfs size (e.g. 256m, 512m)").option("--stdin <data>", "Data to pipe to stdin").option("--install <package>", "Install package for runtime (repeatable)", collect, []).option("--host <url>", "Execute on remote server").option("--key <key>", "API key for remote server").action(async (file, opts) => {
61224
+ program2.command("run").description("Execute code in isol8").argument("[file]", "Script file to execute").option("-e, --eval <code>", "Execute inline code string").option("-r, --runtime <name>", "Force runtime (python, node, bun, deno, bash)").option("--net <mode>", "Network mode: none, host, filtered", "none").option("--allow <regex>", "Whitelist regex for filtered mode (repeatable)", collect, []).option("--deny <regex>", "Blacklist regex for filtered mode (repeatable)", collect, []).option("--out <file>", "Write output to file").option("--persistent", "Use persistent container").option("--timeout <ms>", "Execution timeout in milliseconds").option("--memory <limit>", "Memory limit (e.g. 512m, 1g)").option("--cpu <limit>", "CPU limit as fraction (e.g. 0.5, 2.0)").option("--image <name>", "Override Docker image").option("--pids-limit <n>", "Maximum number of processes").option("--writable", "Disable read-only root filesystem").option("--max-output <bytes>", "Maximum output size in bytes").option("--secret <KEY=VALUE>", "Secret env var (repeatable, values masked)", collect, []).option("--sandbox-size <size>", "Sandbox tmpfs size (e.g. 128m)").option("--tmp-size <size>", "Tmp tmpfs size (e.g. 256m, 512m)").option("--stdin <data>", "Data to pipe to stdin").option("--install <package>", "Install package for runtime (repeatable)", collect, []).option("--host <url>", "Execute on remote server").option("--key <key>", "API key for remote server").option("--stream", "Stream output in real-time").action(async (file, opts) => {
61222
61225
  const { code, runtime, engineOptions, engine, stdinData } = await resolveRunInput(file, opts);
61223
61226
  const spinner = ora("Starting execution...").start();
61224
61227
  try {
@@ -61231,23 +61234,42 @@ program2.command("run").description("Execute code in isol8").argument("[file]",
61231
61234
  ...stdinData ? { stdin: stdinData } : {},
61232
61235
  ...opts.install.length > 0 ? { installPackages: opts.install } : {}
61233
61236
  };
61234
- const result = await engine.execute(req);
61235
- spinner.stop();
61236
- if (result.stdout) {
61237
- console.log(result.stdout);
61238
- }
61239
- if (result.stderr) {
61240
- console.error(result.stderr);
61241
- }
61242
- if (result.truncated) {
61243
- console.error("[WARN] Output was truncated");
61244
- }
61245
- if (opts.out && result.stdout) {
61246
- writeFileSync(opts.out, result.stdout, "utf-8");
61247
- console.error(`[INFO] Output written to ${opts.out}`);
61248
- }
61249
- if (result.exitCode !== 0) {
61250
- process.exit(result.exitCode);
61237
+ if (opts.stream) {
61238
+ spinner.stop();
61239
+ const stream = engine.executeStream(req);
61240
+ for await (const event of stream) {
61241
+ if (event.type === "stdout") {
61242
+ process.stdout.write(event.data);
61243
+ } else if (event.type === "stderr") {
61244
+ process.stderr.write(event.data);
61245
+ } else if (event.type === "exit") {
61246
+ if (event.data !== "0") {
61247
+ process.exit(Number.parseInt(event.data, 10));
61248
+ }
61249
+ } else if (event.type === "error") {
61250
+ console.error(`[ERR] ${event.data}`);
61251
+ process.exit(1);
61252
+ }
61253
+ }
61254
+ } else {
61255
+ const result = await engine.execute(req);
61256
+ spinner.stop();
61257
+ if (result.stdout) {
61258
+ console.log(result.stdout);
61259
+ }
61260
+ if (result.stderr) {
61261
+ console.error(result.stderr);
61262
+ }
61263
+ if (result.truncated) {
61264
+ console.error("[WARN] Output was truncated");
61265
+ }
61266
+ if (opts.out && result.stdout) {
61267
+ writeFileSync(opts.out, result.stdout, "utf-8");
61268
+ console.error(`[INFO] Output written to ${opts.out}`);
61269
+ }
61270
+ if (result.exitCode !== 0) {
61271
+ process.exit(result.exitCode);
61272
+ }
61251
61273
  }
61252
61274
  } catch (err) {
61253
61275
  spinner.stop();
@@ -61483,4 +61505,4 @@ if (!process.argv.slice(2).length) {
61483
61505
  }
61484
61506
  program2.parse();
61485
61507
 
61486
- //# debugId=420EBE4C8706C16E64756E2164756E21
61508
+ //# debugId=32DEDFAE67B3C8B564756E2164756E21