just-bash 2.14.0 → 2.15.1-executor.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.
Files changed (40) hide show
  1. package/dist/Bash.d.ts +88 -0
  2. package/dist/bin/chunks/chunk-MNMRGJJM.js +11 -0
  3. package/dist/bin/chunks/js-exec-RGKNWHHL.js +100 -0
  4. package/dist/bin/chunks/js-exec-worker.js +233 -1
  5. package/dist/bin/chunks/{python3-VCIXXAXF.js → python3-QOJU2POC.js} +1 -1
  6. package/dist/bin/chunks/worker.js +15 -1
  7. package/dist/bin/just-bash.js +238 -238
  8. package/dist/bin/shell/chunks/chunk-MNMRGJJM.js +11 -0
  9. package/dist/bin/shell/chunks/js-exec-DUGJM6RL.js +100 -0
  10. package/dist/bin/shell/chunks/{python3-KFZH67GD.js → python3-O4VTP6TD.js} +1 -1
  11. package/dist/bin/shell/shell.js +113 -113
  12. package/dist/bundle/browser.js +6 -6
  13. package/dist/bundle/chunks/chunk-B6O2PIY4.js +10 -0
  14. package/dist/bundle/chunks/js-exec-LSIPMWTQ.js +99 -0
  15. package/dist/bundle/chunks/js-exec-worker.js +233 -1
  16. package/dist/bundle/chunks/{python3-SG3DOKBZ.js → python3-5F2XPEW4.js} +1 -1
  17. package/dist/bundle/chunks/worker.js +15 -1
  18. package/dist/bundle/index.cjs +666 -663
  19. package/dist/bundle/index.js +49 -49
  20. package/dist/commands/js-exec/executor-adapter.d.ts +66 -0
  21. package/dist/commands/js-exec/js-exec.d.ts +19 -1
  22. package/dist/commands/js-exec/worker.d.ts +8 -0
  23. package/dist/commands/worker-bridge/bridge-handler.d.ts +3 -1
  24. package/dist/commands/worker-bridge/protocol.d.ts +1 -0
  25. package/dist/commands/worker-bridge/sync-backend.d.ts +5 -0
  26. package/dist/executor-init.d.ts +19 -0
  27. package/dist/interpreter/interpreter.d.ts +7 -0
  28. package/dist/interpreter/types.d.ts +10 -0
  29. package/dist/types.d.ts +17 -0
  30. package/package.json +37 -34
  31. package/vendor/cpython-emscripten/python.wasm +0 -0
  32. package/vendor/executor/executor-sdk-bundle.d.mts +18 -0
  33. package/vendor/executor/executor-sdk-bundle.mjs +512 -0
  34. package/vendor/executor/openapi-extractor-wasm/openapi_extractor_bg.wasm +0 -0
  35. package/dist/bin/chunks/chunk-3KAVXQP4.js +0 -11
  36. package/dist/bin/chunks/js-exec-BDQGEAU6.js +0 -97
  37. package/dist/bin/shell/chunks/chunk-3KAVXQP4.js +0 -11
  38. package/dist/bin/shell/chunks/js-exec-HPXZV7UJ.js +0 -97
  39. package/dist/bundle/chunks/chunk-S4EYC6T6.js +0 -10
  40. package/dist/bundle/chunks/js-exec-4CW5N6RM.js +0 -96
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import{a as F}from"./chunk-4OALHZXB.js";import{a as w,b as h}from"./chunk-LIYVQA3X.js";import{a as T,b as g}from"./chunk-OOJCYVYF.js";import{a as m}from"./chunk-RLNOQILG.js";var n={NOOP:0,READ_FILE:1,WRITE_FILE:2,STAT:3,READDIR:4,MKDIR:5,RM:6,EXISTS:7,APPEND_FILE:8,SYMLINK:9,READLINK:10,LSTAT:11,CHMOD:12,REALPATH:13,RENAME:14,COPY_FILE:15,WRITE_STDOUT:100,WRITE_STDERR:101,EXIT:102,HTTP_REQUEST:200,EXEC_COMMAND:300,INVOKE_TOOL:400},r={PENDING:0,READY:1,SUCCESS:2,ERROR:3},l={NONE:0,NOT_FOUND:1,IS_DIRECTORY:2,NOT_DIRECTORY:3,EXISTS:4,PERMISSION_DENIED:5,INVALID_PATH:6,IO_ERROR:7,TIMEOUT:8,NETWORK_ERROR:9,NETWORK_NOT_CONFIGURED:10},o={OP_CODE:0,STATUS:4,PATH_LENGTH:8,DATA_LENGTH:12,RESULT_LENGTH:16,ERROR_CODE:20,FLAGS:24,MODE:28,PATH_BUFFER:32,DATA_BUFFER:4128},p={CONTROL_REGION:32,PATH_BUFFER:4096,DATA_BUFFER:1048576,TOTAL:1052704},S={NONE:0,RECURSIVE:1,FORCE:2,MKDIR_RECURSIVE:1},u={IS_FILE:0,IS_DIRECTORY:1,IS_SYMLINK:2,MODE:4,SIZE:8,MTIME:16,TOTAL:24};function _(){return new w(p.TOTAL)}var R=class{int32View;uint8View;dataView;constructor(t){this.int32View=new Int32Array(t),this.uint8View=new Uint8Array(t),this.dataView=new DataView(t)}getOpCode(){return h.load(this.int32View,o.OP_CODE/4)}setOpCode(t){h.store(this.int32View,o.OP_CODE/4,t)}getStatus(){return h.load(this.int32View,o.STATUS/4)}setStatus(t){h.store(this.int32View,o.STATUS/4,t)}getPathLength(){return h.load(this.int32View,o.PATH_LENGTH/4)}setPathLength(t){h.store(this.int32View,o.PATH_LENGTH/4,t)}getDataLength(){return h.load(this.int32View,o.DATA_LENGTH/4)}setDataLength(t){h.store(this.int32View,o.DATA_LENGTH/4,t)}getResultLength(){return h.load(this.int32View,o.RESULT_LENGTH/4)}setResultLength(t){h.store(this.int32View,o.RESULT_LENGTH/4,t)}getErrorCode(){return h.load(this.int32View,o.ERROR_CODE/4)}setErrorCode(t){h.store(this.int32View,o.ERROR_CODE/4,t)}getFlags(){return h.load(this.int32View,o.FLAGS/4)}setFlags(t){h.store(this.int32View,o.FLAGS/4,t)}getMode(){return h.load(this.int32View,o.MODE/4)}setMode(t){h.store(this.int32View,o.MODE/4,t)}getPath(){let t=this.getPathLength(),e=this.uint8View.slice(o.PATH_BUFFER,o.PATH_BUFFER+t);return new TextDecoder().decode(e)}setPath(t){let e=new TextEncoder().encode(t);if(e.length>p.PATH_BUFFER)throw new Error(`Path too long: ${e.length} > ${p.PATH_BUFFER}`);this.uint8View.set(e,o.PATH_BUFFER),this.setPathLength(e.length)}getData(){let t=this.getDataLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setData(t){if(t.length>p.DATA_BUFFER)throw new Error(`Data too large: ${t.length} > ${p.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setDataLength(t.length)}getDataAsString(){let t=this.getData();return new TextDecoder().decode(t)}setDataFromString(t){let e=new TextEncoder().encode(t);this.setData(e)}getResult(){let t=this.getResultLength();return this.uint8View.slice(o.DATA_BUFFER,o.DATA_BUFFER+t)}setResult(t){if(t.length>p.DATA_BUFFER)throw new Error(`Result too large: ${t.length} > ${p.DATA_BUFFER}`);this.uint8View.set(t,o.DATA_BUFFER),this.setResultLength(t.length)}getResultAsString(){let t=this.getResult();return new TextDecoder().decode(t)}setResultFromString(t){let e=new TextEncoder().encode(t);this.setResult(e)}encodeStat(t){this.uint8View[o.DATA_BUFFER+u.IS_FILE]=t.isFile?1:0,this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]=t.isDirectory?1:0,this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]=t.isSymbolicLink?1:0,this.dataView.setInt32(o.DATA_BUFFER+u.MODE,t.mode,!0);let e=Math.min(t.size,Number.MAX_SAFE_INTEGER);this.dataView.setFloat64(o.DATA_BUFFER+u.SIZE,e,!0),this.dataView.setFloat64(o.DATA_BUFFER+u.MTIME,t.mtime.getTime(),!0),this.setResultLength(u.TOTAL)}decodeStat(){return{isFile:this.uint8View[o.DATA_BUFFER+u.IS_FILE]===1,isDirectory:this.uint8View[o.DATA_BUFFER+u.IS_DIRECTORY]===1,isSymbolicLink:this.uint8View[o.DATA_BUFFER+u.IS_SYMLINK]===1,mode:this.dataView.getInt32(o.DATA_BUFFER+u.MODE,!0),size:this.dataView.getFloat64(o.DATA_BUFFER+u.SIZE,!0),mtime:new Date(this.dataView.getFloat64(o.DATA_BUFFER+u.MTIME,!0))}}waitForReady(t){return h.wait(this.int32View,o.STATUS/4,r.PENDING,t)}waitForReadyAsync(t){return h.waitAsync(this.int32View,o.STATUS/4,r.PENDING,t)}async waitUntilReady(t){let e=Date.now();for(;;){let a=this.getStatus();if(a===r.READY)return!0;let s=Date.now()-e;if(s>=t)return!1;let i=t-s,c=h.waitAsync(this.int32View,o.STATUS/4,a,i);if(c.async&&await c.value==="timed-out")return!1}}waitForResult(t){return h.wait(this.int32View,o.STATUS/4,r.READY,t)}notify(){return h.notify(this.int32View,o.STATUS/4)}reset(){this.setOpCode(n.NOOP),this.setStatus(r.PENDING),this.setPathLength(0),this.setDataLength(0),this.setResultLength(0),this.setErrorCode(l.NONE),this.setFlags(S.NONE),this.setMode(0)}};var O=class{fs;cwd;commandName;secureFetch;maxOutputSize;exec;invokeTool;protocol;running=!1;output={stdout:"",stderr:"",exitCode:0};outputLimitExceeded=!1;startTime=0;timeoutMs=0;constructor(t,e,a,s,i=void 0,c=0,d=void 0,E=void 0){this.fs=e,this.cwd=a,this.commandName=s,this.secureFetch=i,this.maxOutputSize=c,this.exec=d,this.invokeTool=E,this.protocol=new R(t)}remainingMs(){return Math.max(0,this.timeoutMs-(Date.now()-this.startTime))}raceDeadline(t){let e=this.remainingMs();if(e<=0)return this.running=!1,this.output.exitCode=124,this.output.stderr+=`
3
+ ${this.commandName}: execution timeout exceeded
4
+ `,Promise.reject(new Error("Operation timed out"));let a=t();return new Promise((s,i)=>{let c=T(()=>{this.running=!1,this.output.exitCode=124,this.output.stderr+=`
5
+ ${this.commandName}: execution timeout exceeded
6
+ `,i(new Error("Operation timed out"))},e);a.then(d=>{g(c),s(d)},d=>{g(c),i(d)})})}async run(t){for(this.running=!0,this.startTime=Date.now(),this.timeoutMs=t;this.running;){if(Date.now()-this.startTime>=t){this.output.stderr+=`
7
+ ${this.commandName}: execution timeout exceeded
8
+ `,this.output.exitCode=124;break}let a=this.remainingMs();if(!await this.protocol.waitUntilReady(a)){this.output.stderr+=`
9
+ ${this.commandName}: execution timeout exceeded
10
+ `,this.output.exitCode=124;break}let i=this.protocol.getOpCode();await this.handleOperation(i),this.protocol.notify()}return this.output}stop(){this.running=!1}async handleOperation(t){try{switch(t){case n.READ_FILE:await this.handleReadFile();break;case n.WRITE_FILE:await this.handleWriteFile();break;case n.STAT:await this.handleStat();break;case n.LSTAT:await this.handleLstat();break;case n.READDIR:await this.handleReaddir();break;case n.MKDIR:await this.handleMkdir();break;case n.RM:await this.handleRm();break;case n.EXISTS:await this.handleExists();break;case n.APPEND_FILE:await this.handleAppendFile();break;case n.SYMLINK:await this.handleSymlink();break;case n.READLINK:await this.handleReadlink();break;case n.CHMOD:await this.handleChmod();break;case n.REALPATH:await this.handleRealpath();break;case n.RENAME:await this.handleRename();break;case n.COPY_FILE:await this.handleCopyFile();break;case n.WRITE_STDOUT:this.handleWriteStdout();break;case n.WRITE_STDERR:this.handleWriteStderr();break;case n.EXIT:this.handleExit();break;case n.HTTP_REQUEST:await this.handleHttpRequest();break;case n.EXEC_COMMAND:await this.handleExecCommand();break;case n.INVOKE_TOOL:await this.handleInvokeTool();break;default:this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setStatus(r.ERROR)}}catch(e){this.setErrorFromException(e)}}resolvePath(t){return this.fs.resolvePath(this.cwd,t)}async handleReadFile(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readFileBuffer(t);this.protocol.setResult(e),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleWriteFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.writeFile(t,e),this.protocol.setStatus(r.SUCCESS)}catch(a){this.setErrorFromException(a)}}async handleStat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.stat(t);this.protocol.encodeStat(e),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleLstat(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.lstat(t);this.protocol.encodeStat(e),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleReaddir(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readdir(t);this.protocol.setResultFromString(JSON.stringify(e)),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleMkdir(){let t=this.resolvePath(this.protocol.getPath()),a=(this.protocol.getFlags()&S.MKDIR_RECURSIVE)!==0;try{await this.fs.mkdir(t,{recursive:a}),this.protocol.setStatus(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleRm(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getFlags(),a=(e&S.RECURSIVE)!==0,s=(e&S.FORCE)!==0;try{await this.fs.rm(t,{recursive:a,force:s}),this.protocol.setStatus(r.SUCCESS)}catch(i){this.setErrorFromException(i)}}async handleExists(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.exists(t);this.protocol.setResult(new Uint8Array([e?1:0])),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleAppendFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getData();try{await this.fs.appendFile(t,e),this.protocol.setStatus(r.SUCCESS)}catch(a){this.setErrorFromException(a)}}async handleSymlink(){let t=this.protocol.getPath(),e=this.protocol.getDataAsString(),a=this.resolvePath(t);try{await this.fs.symlink(e,a),this.protocol.setStatus(r.SUCCESS)}catch(s){this.setErrorFromException(s)}}async handleReadlink(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.readlink(t);this.protocol.setResultFromString(e),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleChmod(){let t=this.resolvePath(this.protocol.getPath()),e=this.protocol.getMode();try{await this.fs.chmod(t,e),this.protocol.setStatus(r.SUCCESS)}catch(a){this.setErrorFromException(a)}}async handleRealpath(){let t=this.resolvePath(this.protocol.getPath());try{let e=await this.fs.realpath(t);this.protocol.setResultFromString(e),this.protocol.setStatus(r.SUCCESS)}catch(e){this.setErrorFromException(e)}}async handleRename(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.mv(t,e),this.protocol.setStatus(r.SUCCESS)}catch(a){this.setErrorFromException(a)}}async handleCopyFile(){let t=this.resolvePath(this.protocol.getPath()),e=this.resolvePath(this.protocol.getDataAsString());try{await this.fs.cp(t,e),this.protocol.setStatus(r.SUCCESS)}catch(a){this.setErrorFromException(a)}}handleWriteStdout(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stdout",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setStatus(r.ERROR);return}this.protocol.setStatus(r.SUCCESS)}handleWriteStderr(){let t=this.protocol.getDataAsString();if(!this.tryAppendOutput("stderr",t)){this.outputLimitExceeded=!0,this.output.exitCode=1,this.appendOutputLimitError(),this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Output size limit exceeded"),this.protocol.setStatus(r.ERROR);return}this.protocol.setStatus(r.SUCCESS)}handleExit(){let t=this.protocol.getFlags();this.outputLimitExceeded?this.output.exitCode===0&&(this.output.exitCode=1):this.output.exitCode=t,this.protocol.setStatus(r.SUCCESS),this.running=!1}tryAppendOutput(t,e){return this.outputLimitExceeded?!1:this.maxOutputSize<=0?(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0):this.output.stdout.length+this.output.stderr.length+e.length>this.maxOutputSize?!1:(t==="stdout"?this.output.stdout+=e:this.output.stderr+=e,!0)}appendOutputLimitError(){if(this.maxOutputSize<=0)return;let t=`${this.commandName}: total output size exceeded (>${this.maxOutputSize} bytes), increase executionLimits.maxOutputSize
11
+ `,e=t.length>this.maxOutputSize?t.slice(0,this.maxOutputSize):t;if(this.output.stderr.includes("total output size exceeded"))return;let s=this.output.stdout.length+this.output.stderr.length+e.length-this.maxOutputSize;if(s>0)if(this.output.stdout.length>=s)this.output.stdout=this.output.stdout.slice(0,this.output.stdout.length-s);else{let i=s-this.output.stdout.length;this.output.stdout="",i>=this.output.stderr.length?this.output.stderr="":this.output.stderr=this.output.stderr.slice(0,this.output.stderr.length-i)}this.output.stderr+=e}async handleHttpRequest(){let t=this.secureFetch;if(!t){this.protocol.setErrorCode(l.NETWORK_NOT_CONFIGURED),this.protocol.setResultFromString("Network access not configured. Enable network in Bash options."),this.protocol.setStatus(r.ERROR);return}let e=this.protocol.getPath(),a=this.protocol.getDataAsString();try{let s=a?JSON.parse(a):{},i=this.remainingMs(),c=await this.raceDeadline(()=>t(e,{method:s.method,headers:s.headers,body:s.body,timeoutMs:i})),d=JSON.stringify({status:c.status,statusText:c.statusText,headers:c.headers,body:c.body,url:c.url});this.protocol.setResultFromString(d),this.protocol.setStatus(r.SUCCESS)}catch(s){let i=m(s instanceof Error?s.message:String(s));this.protocol.setErrorCode(l.NETWORK_ERROR),this.protocol.setResultFromString(i),this.protocol.setStatus(r.ERROR)}}async handleExecCommand(){let t=this.exec;if(!t){this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Command execution not available in this context."),this.protocol.setStatus(r.ERROR);return}let e=this.protocol.getPath(),a=this.protocol.getDataAsString(),s=new AbortController;try{let i={cwd:this.cwd,signal:s.signal};if(a){let E=JSON.parse(a);E.stdin&&(i.stdin=E.stdin),E.args&&Array.isArray(E.args)&&(i.args=E.args.map(D=>String(D)),e=F([e]))}let c=await this.raceDeadline(()=>t(e,i)),d=JSON.stringify({stdout:c.stdout,stderr:c.stderr,exitCode:c.exitCode});this.protocol.setResultFromString(d),this.protocol.setStatus(r.SUCCESS)}catch(i){s.abort();let c=i instanceof Error?i.message:String(i);this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString(c),this.protocol.setStatus(r.ERROR)}}async handleInvokeTool(){let t=this.invokeTool;if(!t){this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString("Tool invocation not available in this context."),this.protocol.setStatus(r.ERROR);return}let e=this.protocol.getPath(),a=this.protocol.getDataAsString();try{let s=await this.raceDeadline(()=>t(e,a));this.protocol.setResultFromString(s),this.protocol.setStatus(r.SUCCESS)}catch(s){let i=s instanceof Error?s.message:String(s);this.protocol.setErrorCode(l.IO_ERROR),this.protocol.setResultFromString(i),this.protocol.setStatus(r.ERROR)}}setErrorFromException(t){let e=t instanceof Error?t.message:String(t),a=m(e),s=l.IO_ERROR,i=e.toLowerCase();i.includes("no such file")||i.includes("not found")||i.includes("enoent")?s=l.NOT_FOUND:i.includes("is a directory")||i.includes("eisdir")?s=l.IS_DIRECTORY:i.includes("not a directory")||i.includes("enotdir")?s=l.NOT_DIRECTORY:i.includes("already exists")||i.includes("eexist")?s=l.EXISTS:(i.includes("permission")||i.includes("eperm")||i.includes("eacces"))&&(s=l.PERMISSION_DENIED),this.protocol.setErrorCode(s),this.protocol.setResultFromString(a),this.protocol.setStatus(r.ERROR)}};export{_ as a,O as b};
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ import{a as F,b as W}from"./chunk-MNMRGJJM.js";import"./chunk-4OALHZXB.js";import"./chunk-D64U2VGQ.js";import"./chunk-LIYVQA3X.js";import{a as T,b as E}from"./chunk-OOJCYVYF.js";import{a as M}from"./chunk-4PRVMER6.js";import{b as L}from"./chunk-YU6OGPZR.js";import{a as O,b as k}from"./chunk-RLNOQILG.js";import{a as j}from"./chunk-4VDEBYW7.js";import{b as B}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{AsyncLocalStorage as H}from"node:async_hooks";import{randomBytes as q}from"node:crypto";import{fileURLToPath as N}from"node:url";import{Worker as D}from"node:worker_threads";var _=1e4,I=6e4,R=new H,J=`js-exec - Sandboxed JavaScript/TypeScript runtime with Node.js-compatible APIs
3
+
4
+ Usage: js-exec [OPTIONS] [-c CODE | FILE] [ARGS...]
5
+
6
+ Options:
7
+ -c CODE Execute inline code
8
+ -m, --module Enable ES module mode (import/export)
9
+ --strip-types Strip TypeScript type annotations
10
+ --version, -V Show version
11
+ --help Show this help
12
+
13
+ Examples:
14
+ js-exec -c "console.log(1 + 2)"
15
+ js-exec script.js
16
+ js-exec app.ts
17
+ echo 'console.log("hello")' | js-exec
18
+
19
+ File Extension Auto-Detection:
20
+ .js script mode (module mode if top-level await detected)
21
+ .mjs ES module mode
22
+ .ts, .mts ES module mode + TypeScript stripping
23
+
24
+ Node.js Compatibility:
25
+ Code written for Node.js largely works here. Both require and import
26
+ are supported, the node: prefix works, and standard globals like process,
27
+ console, and fetch are available. All I/O is synchronous.
28
+
29
+ Available modules:
30
+ fs, path, child_process, process, console,
31
+ os, url, assert, util, events, buffer, stream,
32
+ string_decoder, querystring
33
+
34
+ fs (global, require('fs'), or import from 'node:fs'):
35
+ readFileSync, writeFileSync, appendFileSync, copyFileSync, renameSync
36
+ readdirSync, mkdirSync, rmSync, unlinkSync, rmdirSync
37
+ statSync, lstatSync, existsSync, realpathSync, chmodSync
38
+ symlinkSync, readlinkSync, readFileBuffer
39
+ fs.promises.readFile, fs.promises.writeFile, fs.promises.access, ...
40
+
41
+ path: join, resolve, dirname, basename, extname, normalize,
42
+ relative, isAbsolute, parse, format, sep, delimiter
43
+
44
+ child_process:
45
+ execSync(cmd) throws on non-zero exit, returns stdout
46
+ spawnSync(cmd, args) returns { stdout, stderr, status }
47
+
48
+ process (also global): argv, cwd(), exit(), env, platform, arch,
49
+ version, versions
50
+
51
+ os: platform(), arch(), homedir(), tmpdir(), type(), hostname(),
52
+ EOL, cpus(), endianness()
53
+
54
+ url: URL, URLSearchParams, parse(), format()
55
+
56
+ assert: ok(), equal(), strictEqual(), deepEqual(), throws(),
57
+ doesNotThrow(), fail()
58
+
59
+ util: format(), inspect(), promisify(), types, inherits()
60
+
61
+ events: EventEmitter (on, once, emit, off, removeListener, ...)
62
+
63
+ buffer: Buffer.from(), Buffer.alloc(), Buffer.concat(),
64
+ Buffer.isBuffer(), toString(), slice(), equals()
65
+
66
+ stream: Readable, Writable, Duplex, Transform, PassThrough, pipeline
67
+
68
+ string_decoder: StringDecoder (write, end)
69
+
70
+ querystring: parse(), stringify(), escape(), unescape()
71
+
72
+ Other Globals:
73
+ console log (stdout), error/warn (stderr)
74
+ fetch(url, opts) HTTP; returns Promise<Response> (Web Fetch API)
75
+ URL, URLSearchParams, Headers, Request, Response
76
+ Buffer Buffer.from(), Buffer.alloc(), etc.
77
+
78
+ Not Available:
79
+ http, https, net, tls, crypto, zlib, dns, cluster, worker_threads,
80
+ vm, v8, readline, and other Node.js built-in modules that require
81
+ native bindings. Use fetch() for HTTP requests.
82
+
83
+ Limits:
84
+ Memory: 64 MB per execution
85
+ Timeout: 10 s (60 s with network; configurable via maxJsTimeoutMs)
86
+ Engine: QuickJS (compiled to WebAssembly)
87
+ `;function z(t){let e={code:null,scriptFile:null,showVersion:!1,scriptArgs:[],isModule:!1,stripTypes:!1};if(t.length===0)return e;for(let r=0;r<t.length;r++){let o=t[r];if(o==="-m"||o==="--module"){e.isModule=!0;continue}if(o==="--strip-types"){e.stripTypes=!0;continue}if(o==="-c")return r+1>=t.length?{stdout:"",stderr:`js-exec: option requires an argument -- 'c'
88
+ `,exitCode:2}:(e.code=t[r+1],e.scriptArgs=t.slice(r+2),e);if(o==="--version"||o==="-V")return e.showVersion=!0,e;if(o.startsWith("-")&&o!=="-"&&o!=="--")return{stdout:"",stderr:`js-exec: unrecognized option '${o}'
89
+ `,exitCode:2};if(o==="--")return r+1<t.length&&(e.scriptFile=t[r+1],e.scriptArgs=t.slice(r+2)),e;if(!o.startsWith("-"))return e.scriptFile=o,e.scriptArgs=t.slice(r+1),e}return e}var i=null,b=null,a=[],n=null,V=N(new URL("./worker.js",import.meta.url));function w(){for(;a.length>0&&a[0].canceled;)a.shift();if(n||a.length===0)return;let t=a.shift();if(!t)return;n=t,G().postMessage(n.input)}function Q(t,e){if(!t||typeof t!="object")return{success:!1,error:"Malformed worker response"};let r=t;if(typeof r.protocolToken!="string"||r.protocolToken!==e)return{success:!1,error:"Malformed worker response: invalid protocol token"};if(typeof r.success!="boolean")return{success:!1,error:"Malformed worker response: missing success flag"};if(r.success){let o={success:!0},s=t;return typeof s.executorResult=="string"&&(o.executorResult=s.executorResult),Array.isArray(s.executorLogs)&&(o.executorLogs=s.executorLogs),o}return{success:!1,error:typeof r.error=="string"&&r.error.length>0?r.error:"Worker execution failed"}}function G(){if(b&&(E(b),b=null),i)return i;let t=L.runTrusted(()=>new D(V));return i=t,t.on("message",e=>{if(i===t){if(n){let r=Q(e,n.input.protocolToken);n.resolve(r),n=null}a.length>0?w():K()}}),t.on("error",e=>{if(i===t){if(n){let r=k(j(e));n.resolve({success:!1,error:r}),n=null}for(let r of a)r.resolve({success:!1,error:"Worker crashed"});a.length=0,i=null}}),t.on("exit",()=>{i===t&&(i=null,n&&(n.resolve({success:!1,error:"Worker exited unexpectedly"}),n=null),a.length>0&&w())}),t}function K(){b=T(()=>{i&&!n&&a.length===0&&(i.terminate(),i=null)},5e3)}async function X(t,e,r,o=[],s,d,f){return R.getStore()?{stdout:"",stderr:`js-exec: recursive invocation is not supported
90
+ `,exitCode:1}:Y(t,e,r,o,s,d,f)}async function Y(t,e,r,o=[],s,d,f){let y=F(),u=e.exec,h=u?(m,P)=>R.run(!0,()=>u(m,P)):void 0,l=new W(y,e.fs,e.cwd,"js-exec",e.fetch,e.limits?.maxOutputSize??0,h,e.executorInvokeTool),x=e.limits?.maxJsTimeoutMs??_,g=e.fetch?Math.max(x,I):x,c={protocolToken:q(16).toString("hex"),sharedBuffer:y,jsCode:t,cwd:e.cwd,env:M(e.env),args:o,scriptPath:r,bootstrapCode:s,isModule:d,stripTypes:f,timeoutMs:g,hasExecutorTools:e.executorInvokeTool!==void 0},A,U=new Promise(m=>{A=m}),S={input:c,resolve:()=>{}},$=T(()=>{if(n===S){let m=i;m&&(i=null,m.terminate()),n=null,w()}else S.canceled=!0,n||w();S.resolve({success:!1,error:`Execution timeout: exceeded ${g}ms limit`})},g);S.resolve=m=>{E($),A(m)},a.push(S),w();let[v,C]=await Promise.all([l.run(g),U.catch(m=>({success:!1,error:k(j(m))}))]);return!C.success&&C.error?{stdout:v.stdout,stderr:`${v.stderr}js-exec: ${k(C.error)}
91
+ `,exitCode:v.exitCode||1}:v}async function de(t,e,r){if(R.getStore())return{result:null,error:"js-exec: recursive invocation is not supported"};let o=F(),s=new W(o,e.fs,e.cwd,"js-exec",e.fetch,e.limits?.maxOutputSize??0,void 0,r),d=e.limits?.maxJsTimeoutMs??_,f=e.fetch?Math.max(d,I):d,u={protocolToken:q(16).toString("hex"),sharedBuffer:o,jsCode:t,cwd:e.cwd,env:M(e.env),args:[],executorMode:!0,timeoutMs:f},h,l=new Promise(c=>{h=c}),x={input:u,resolve:()=>{}},g=T(()=>{if(n===x){let c=i;c&&(i=null,c.terminate()),n=null,w()}else x.canceled=!0,n||w();x.resolve({success:!1,error:`Execution timeout: exceeded ${f}ms limit`})},f);x.resolve=c=>{E(g),h(c)},a.push(x),w();let[,p]=await Promise.all([s.run(f),l.catch(c=>({success:!1,error:k(j(c))}))]);if("executorLogs"in p||"executorResult"in p){if(p.error)return{result:null,error:p.error,logs:p.executorLogs};let c;if(p.executorResult!==void 0)try{c=JSON.parse(p.executorResult)}catch{c=p.executorResult}return{result:c??null,logs:p.executorLogs}}return{result:null,error:p.error||"Unknown execution error"}}var fe={name:"js-exec",async execute(t,e){if(B(t))return{stdout:J,stderr:"",exitCode:0};let r=z(t);if("exitCode"in r)return r;if(r.showVersion)return{stdout:`QuickJS (quickjs-emscripten)
92
+ `,stderr:"",exitCode:0};let o,s;if(r.code!==null)o=r.code,s="-c";else if(r.scriptFile!==null){let u=e.fs.resolvePath(e.cwd,r.scriptFile);if(!await e.fs.exists(u))return{stdout:"",stderr:`js-exec: can't open file '${r.scriptFile}': No such file or directory
93
+ `,exitCode:2};try{o=await e.fs.readFile(u),s=u}catch(h){return{stdout:"",stderr:`js-exec: can't open file '${r.scriptFile}': ${O(h.message)}
94
+ `,exitCode:2}}}else if(e.stdin.trim())o=e.stdin,s="<stdin>";else return{stdout:"",stderr:`js-exec: no input provided (use -c CODE or provide a script file)
95
+ `,exitCode:2};let d=r.isModule,f=r.stripTypes;if(s&&s!=="-c"&&s!=="<stdin>"&&((s.endsWith(".mjs")||s.endsWith(".mts")||s.endsWith(".ts"))&&(d=!0),(s.endsWith(".ts")||s.endsWith(".mts"))&&(f=!0)),!d&&/\bawait\s+[\w([`]/.test(o)&&(d=!0),e.executorExecFn){let u=await e.executorExecFn(o),h=u.logs??[];return{stdout:h.filter(l=>!l.startsWith("[error]")&&!l.startsWith("[warn]")).map(l=>`${l.replace(/^\[(log|info|debug)\] /,"")}
96
+ `).join(""),stderr:u.error?`${u.error}
97
+ `:h.filter(l=>l.startsWith("[error]")||l.startsWith("[warn]")).map(l=>`${l.replace(/^\[(error|warn)\] /,"")}
98
+ `).join(""),exitCode:u.error?1:0}}let y=e.jsBootstrapCode;return X(o,e,s,r.scriptArgs,y,d,f)}},pe={name:"node",async execute(){return{stdout:"",stderr:`node: this sandbox uses js-exec instead of node
99
+
100
+ ${J}`,exitCode:1}}};export{de as executeForExecutor,fe as jsExecCommand,pe as nodeStubCommand};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as _,b as O}from"./chunk-3KAVXQP4.js";import"./chunk-4OALHZXB.js";import"./chunk-D64U2VGQ.js";import"./chunk-LIYVQA3X.js";import{a as v,b as T}from"./chunk-OOJCYVYF.js";import{a as D}from"./chunk-4PRVMER6.js";import{c as y}from"./chunk-MO4RPBN2.js";import{b as C}from"./chunk-YU6OGPZR.js";import{a as M,b as c}from"./chunk-RLNOQILG.js";import{a as E}from"./chunk-4VDEBYW7.js";import{a as b,b as P}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{randomBytes as $}from"node:crypto";import{fileURLToPath as Q}from"node:url";import{Worker as R}from"node:worker_threads";var U=1e4,H=6e4,I={name:"python3",summary:"Execute Python code via CPython Emscripten",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using CPython compiled to WebAssembly via Emscripten.","","This command runs Python in an isolated environment with access to","the virtual filesystem. Standard library modules are available."],options:["-c CODE Execute CODE as Python script","-m MODULE Run library module as a script","--version Show Python version","--help Show this help"],examples:['python3 -c "print(1 + 2)"','python3 -c "import sys; print(sys.version)"',"python3 script.py","python3 script.py arg1 arg2",`echo 'print("hello")' | python3`],notes:["CPython runs in WebAssembly, so execution may be slower than native Python.","Standard library modules are available (no pip install).","Maximum execution time is 30 seconds by default."]};function L(r){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(r.length===0)return e;let t=r.findIndex(o=>!o.startsWith("-")||o==="-"||o==="--");for(let o=0;o<(t===-1?r.length:t);o++){let s=r[o];if(s==="-c")return o+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
2
+ import{a as _,b as O}from"./chunk-MNMRGJJM.js";import"./chunk-4OALHZXB.js";import"./chunk-D64U2VGQ.js";import"./chunk-LIYVQA3X.js";import{a as v,b as T}from"./chunk-OOJCYVYF.js";import{a as D}from"./chunk-4PRVMER6.js";import{c as y}from"./chunk-MO4RPBN2.js";import{b as C}from"./chunk-YU6OGPZR.js";import{a as M,b as c}from"./chunk-RLNOQILG.js";import{a as E}from"./chunk-4VDEBYW7.js";import{a as b,b as P}from"./chunk-GTNBSMZR.js";import"./chunk-KGOUQS5A.js";import{randomBytes as $}from"node:crypto";import{fileURLToPath as Q}from"node:url";import{Worker as R}from"node:worker_threads";var U=1e4,H=6e4,I={name:"python3",summary:"Execute Python code via CPython Emscripten",usage:"python3 [OPTIONS] [-c CODE | -m MODULE | FILE] [ARGS...]",description:["Execute Python code using CPython compiled to WebAssembly via Emscripten.","","This command runs Python in an isolated environment with access to","the virtual filesystem. Standard library modules are available."],options:["-c CODE Execute CODE as Python script","-m MODULE Run library module as a script","--version Show Python version","--help Show this help"],examples:['python3 -c "print(1 + 2)"','python3 -c "import sys; print(sys.version)"',"python3 script.py","python3 script.py arg1 arg2",`echo 'print("hello")' | python3`],notes:["CPython runs in WebAssembly, so execution may be slower than native Python.","Standard library modules are available (no pip install).","Maximum execution time is 30 seconds by default."]};function L(r){let e={code:null,module:null,scriptFile:null,showVersion:!1,scriptArgs:[]};if(r.length===0)return e;let t=r.findIndex(o=>!o.startsWith("-")||o==="-"||o==="--");for(let o=0;o<(t===-1?r.length:t);o++){let s=r[o];if(s==="-c")return o+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'c'
3
3
  `,exitCode:2}:(e.code=r[o+1],e.scriptArgs=r.slice(o+2),e);if(s==="-m")return o+1>=r.length?{stdout:"",stderr:`python3: option requires an argument -- 'm'
4
4
  `,exitCode:2}:(e.module=r[o+1],e.scriptArgs=r.slice(o+2),e);if(s==="--version"||s==="-V")return e.showVersion=!0,e;if(s.startsWith("-")&&s!=="-")return{stdout:"",stderr:`python3: unrecognized option '${s}'
5
5
  `,exitCode:2}}if(t!==-1){let o=r[t];o==="--"?t+1<r.length&&(e.scriptFile=r[t+1],e.scriptArgs=r.slice(t+2)):(e.scriptFile=o,e.scriptArgs=r.slice(t+1))}return e}var k=new WeakMap;function z(r){let e=k.get(r);return e||(e={executionQueue:[],isExecuting:!1},k.set(r,e)),e}function ie(){k=new WeakMap}var N=Q(new URL("./worker.js",import.meta.url));function B(){return $(16).toString("hex")}function V(r,e){if(!r||typeof r!="object")return{success:!1,error:"Malformed worker response"};let t=r;return typeof t.protocolToken!="string"||t.protocolToken!==e?{success:!1,error:"Malformed worker response: invalid protocol token"}:t.type==="security-violation"?{success:!1,error:`Security violation: ${typeof t.violation?.type=="string"?t.violation.type:"unknown"}`}:typeof t.success!="boolean"?{success:!1,error:"Malformed worker response: missing success flag"}:t.success?{success:!0}:{success:!1,error:typeof t.error=="string"&&t.error.length>0?t.error:"Worker execution failed"}}function a(r){if(r.isExecuting||r.executionQueue.length===0)return;for(;r.executionQueue.length>0&&r.executionQueue[0].canceled;)r.executionQueue.shift();if(r.executionQueue.length===0)return;let e=r.executionQueue.shift();if(!e)return;r.isExecuting=!0;let t;try{t=C.runTrusted(()=>new R(N,{workerData:e.input}))}catch(n){let i=n instanceof Error?n.message:String(n);e.resolve({success:!1,error:c(i)}),r.isExecuting=!1,a(r);return}e.workerRef&&(e.workerRef.current=t);let o=y(e.requireDefenseContext,"python3","worker message callback",n=>{e.resolve(V(n,e.input.protocolToken)),r.isExecuting=!1,t.terminate(),a(r)}),s=y(e.requireDefenseContext,"python3","worker error callback",n=>{let i=c(E(n));e.resolve({success:!1,error:i}),r.isExecuting=!1,a(r)}),p=y(e.requireDefenseContext,"python3","worker exit callback",()=>{r.isExecuting&&(e.resolve({success:!1,error:"Worker exited unexpectedly"}),r.isExecuting=!1,a(r))}),f=n=>{try{o(n)}catch(i){let m=i instanceof Error?i.message:String(i);e.resolve({success:!1,error:c(m)}),r.isExecuting=!1,t.terminate(),a(r)}},l=n=>{try{s(n)}catch(i){let m=i instanceof Error?i.message:String(i);e.resolve({success:!1,error:c(m)}),r.isExecuting=!1,a(r)}},g=()=>{try{p()}catch(n){let i=n instanceof Error?n.message:String(n);e.resolve({success:!1,error:c(i)}),r.isExecuting=!1,a(r)}};t.on("message",f),t.on("error",l),t.on("exit",g)}async function j(r,e,t,o=[]){let s=_(),p=new O(s,e.fs,e.cwd,"python3",e.fetch,e.limits?.maxOutputSize??0),f=e.limits?.maxPythonTimeoutMs??U,l=e.fetch?Math.max(f,H):f,g=z(e.fs),n={protocolToken:B(),sharedBuffer:s,pythonCode:r,cwd:e.cwd,env:D(e.env),args:o,scriptPath:t,timeoutMs:l},i={current:null},m=new Promise(u=>{let d={input:n,resolve:()=>{},workerRef:i,requireDefenseContext:e.requireDefenseContext},A=y(e.requireDefenseContext,"python3","worker timeout callback",()=>{i.current?i.current.terminate():d.canceled=!0,u({success:!1,error:`Execution timeout: exceeded ${l}ms limit`})}),F=v(()=>{try{A()}catch(h){let W=h instanceof Error?h.message:String(h);u({success:!1,error:c(W)})}},l);d.resolve=h=>{T(F),u(h)},g.executionQueue.push(d),a(g)}),[x,w]=await Promise.all([p.run(l).catch(u=>({stdout:"",stderr:`python3: bridge error: ${c(E(u))}