{"_id":"@chatfinai/javascript-vm","_rev":"2-668bc7eee2e3982a67a19bd8d69d2cce","name":"@chatfinai/javascript-vm","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@chatfinai/javascript-vm","version":"1.0.0","keywords":["chatfinai","chatfin","javascript","vm","sandbox","nodejs","typescript","isolated-vm","open-source"],"author":{"name":"ChatFinAI","email":"support@chatfin.ai"},"license":"MIT","_id":"@chatfinai/javascript-vm@1.0.0","maintainers":[{"name":"chatfinai","email":"chatfinanceai@gmail.com"}],"homepage":"https://github.com/ChatFinAI/javascript-vm#readme","bugs":{"url":"https://github.com/ChatFinAI/javascript-vm/issues"},"dist":{"shasum":"50508a82e817f1095391a4ac349c523d59bdce67","tarball":"https://registry.npmjs.org/@chatfinai/javascript-vm/-/javascript-vm-1.0.0.tgz","fileCount":23,"integrity":"sha512-+Ag2Nt9KExlMeyhqJJlbrazf5osQBgBuOsfCJwj3WdHAugJr5bCoOyM9dr1YO6Bys2q1xScw76UJLiZt7DasMw==","signatures":[{"sig":"MEUCICSI5KnecM1qdZS7ovL+8AKj9zP0s2JzR+lhZrk7bcJRAiEA8nPvHtBShc9nFjmcfrFGh4A8WUrCjoXSq8NC0XkALM0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24606},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"838f13bbac33e9ec6763ca21c1ef38b4a1fe458c","scripts":{"dev":"ts-node examples/calculator.ts","build":"tsc","clean":"rm -rf dist","prepack":"npm run build","prepare":"npm run build","type-check":"tsc --noEmit"},"_npmUser":{"name":"chatfinai","email":"chatfinanceai@gmail.com"},"repository":{"url":"git+https://github.com/ChatFinAI/javascript-vm.git","type":"git"},"_npmVersion":"10.7.0","description":"A secure, isolated JavaScript VM for Node.js, built with TypeScript. Open source project by ChatFinAI.","directories":{},"_nodeVersion":"18.20.3","dependencies":{"ws":"^8.13.0","isolated-vm":"^5.0.4"},"_hasShrinkwrap":false,"devDependencies":{"ts-node":"^10.9.2","@types/ws":"^8.5.5","typescript":"^5.9.2","@types/node":"^24.5.2"},"_npmOperationalInternal":{"tmp":"tmp/javascript-vm_1.0.0_1758640205092_0.8758079644617471","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@chatfinai/javascript-vm","version":"1.0.1","description":"A secure, isolated JavaScript VM for Node.js, built with TypeScript. Open source project by ChatFinAI.","main":"dist/index.js","types":"dist/index.d.ts","keywords":["chatfinai","chatfin","javascript","vm","sandbox","nodejs","typescript","isolated-vm","open-source"],"author":{"name":"ChatFinAI","email":"support@chatfin.ai"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/ChatFinAI/javascript-vm.git"},"bugs":{"url":"https://github.com/ChatFinAI/javascript-vm/issues"},"homepage":"https://github.com/ChatFinAI/javascript-vm#readme","engines":{"node":">=18.0.0"},"scripts":{"dev":"ts-node examples/calculator.ts","build":"tsc","type-check":"tsc --noEmit","clean":"rm -rf dist","prepare":"npm run build","prepack":"npm run build"},"dependencies":{"isolated-vm":"^5.0.4","ws":"^8.13.0"},"devDependencies":{"@types/node":"^24.5.2","@types/ws":"^8.5.5","ts-node":"^10.9.2","typescript":"^5.9.2"},"_id":"@chatfinai/javascript-vm@1.0.1","gitHead":"ba0c12ea8a448bdc19693e2ae89d079f3bc48482","_nodeVersion":"18.20.3","_npmVersion":"10.7.0","dist":{"integrity":"sha512-YEN6x4ldhiVmD6PdB6wjrsODtsIwnhO5acvjVLC/1N92oHUMQKyJn48lrOXoTcHG0BhmNLGHoyy5pqGI46+7tw==","shasum":"6eb60a2b1c00e9345b4aec430f52bd8b90636caa","tarball":"https://registry.npmjs.org/@chatfinai/javascript-vm/-/javascript-vm-1.0.1.tgz","fileCount":13,"unpackedSize":17149,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIA0JrzyNprX1lI0NO+btvRm5UsD2gfn0EuMJ1SVFcAIoAiA3DP4TmCruQBEAJU+g0GxLX3d/hV64+XzgtXfSVYhHWw=="}]},"_npmUser":{"name":"chatfinai","email":"chatfinanceai@gmail.com"},"directories":{},"maintainers":[{"name":"chatfinai","email":"chatfinanceai@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/javascript-vm_1.0.1_1758640891660_0.5277449144271149"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-23T15:10:05.003Z","modified":"2025-09-23T15:21:32.104Z","1.0.0":"2025-09-23T15:10:05.287Z","1.0.1":"2025-09-23T15:21:31.887Z"},"bugs":{"url":"https://github.com/ChatFinAI/javascript-vm/issues"},"author":{"name":"ChatFinAI","email":"support@chatfin.ai"},"license":"MIT","homepage":"https://github.com/ChatFinAI/javascript-vm#readme","keywords":["chatfinai","chatfin","javascript","vm","sandbox","nodejs","typescript","isolated-vm","open-source"],"repository":{"type":"git","url":"git+https://github.com/ChatFinAI/javascript-vm.git"},"description":"A secure, isolated JavaScript VM for Node.js, built with TypeScript. Open source project by ChatFinAI.","maintainers":[{"name":"chatfinai","email":"chatfinanceai@gmail.com"}],"readme":"# JavaScript VM\n\nA secure, isolated JavaScript VM for Node.js, built with TypeScript. Developed and maintained as an open source project by ChatFinAI.\n\n## Features\n- Run untrusted JavaScript code securely in an isolated VM\n- TypeScript-first development\n- Uses [isolated-vm](https://github.com/laverdet/isolated-vm) for sandboxing\n- WebSocket inspector support for debugging\n- Extensible sandbox API\n\n## Getting Started\n\n### Prerequisites\n- Node.js >= 18\n- npm >= 9\n\n### Installation\n\n#### From npm (Recommended)\n```sh\nnpm install @chatfinai/javascript-vm\n```\n\n#### From source\nClone the repository and install dependencies:\n```sh\ngit clone https://github.com/ChatFinAI/javascript-vm.git\ncd javascript-vm\nnpm install\n```\n\n### Build\n```sh\nnpm run build\n```\n\n### Development\nRun the sample calculator example:\n```sh\nnpm run dev\n```\n\n\n### Debugging\n\n#### Node.js Debugger\nYou can debug the TypeScript code using VS Code or any Node.js debugger:\n```sh\nnode --inspect-brk -r ts-node/register src/index.ts\n```\nThen attach your debugger to `localhost:9229`.\n\n#### WebSocket Inspector (VM Debugging)\nTo enable the VM inspector, instantiate `ExecSandbox` with `debug=true` and specify a port (default: 3000):\n```typescript\nconst sandbox = new ExecSandbox({}, true, 3000);\n```\nThis starts a WebSocket inspector server. You can connect Chrome DevTools to:\n```\ndevtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:3000\n```\nfor live debugging of the isolated VM context.\n\n### Type Checking\n```sh\nnpm run type-check\n```\n\n## Usage Example\n\n### TypeScript\n```typescript\nimport { ExecSandbox, GenDictionary } from '@chatfinai/javascript-vm';\n\nconst calculatorCode = `\n  function add(a, b) { return a + b; }\n  function subtract(a, b) { return a - b; }\n  function multiply(a, b) { return a * b; }\n  function divide(a, b) { return a / b; }\n  result = {\n    add: add(5, 3),\n    subtract: subtract(5, 3),\n    multiply: multiply(5, 3),\n    divide: divide(5, 3)\n  };\n`;\n\nasync function runCalculatorSandbox() {\n  const sandbox = new ExecSandbox(false);\n  try {\n    const output = await sandbox.run(calculatorCode, {} as GenDictionary);\n    console.log(\"Calculator Results:\", output.result);\n  } catch (err) {\n    console.error(\"Sandbox error:\", err);\n  } finally {\n    sandbox.dispose();\n  }\n}\n\nrunCalculatorSandbox();\n```\n\n### JavaScript (CommonJS)\n```javascript\nconst { ExecSandbox } = require('@chatfinai/javascript-vm');\n\nconst calculatorCode = `\n  function add(a, b) { return a + b; }\n  function subtract(a, b) { return a - b; }\n  function multiply(a, b) { return a * b; }\n  function divide(a, b) { return a / b; }\n  result = {\n    add: add(5, 3),\n    subtract: subtract(5, 3),\n    multiply: multiply(5, 3),\n    divide: divide(5, 3)\n  };\n`;\n\nasync function runCalculatorSandbox() {\n  const sandbox = new ExecSandbox(false);\n  try {\n    const output = await sandbox.run(calculatorCode, {});\n    console.log(\"Calculator Results:\", output.result);\n  } catch (err) {\n    console.error(\"Sandbox error:\", err);\n  } finally {\n    sandbox.dispose();\n  }\n}\n\nrunCalculatorSandbox();\n```\n\n## Project Structure\n- `src/VM/` — Core VM and sandbox classes\n- `src/Models/` — Type definitions  \n- `src/index.ts` — Main exports for npm package\n- `examples/` — Calculator usage examples (JavaScript and TypeScript)\n\n## Examples\n\nThe `examples/` directory contains calculator examples showing how to use the VM:\n\n- `calculator.js` — JavaScript (CommonJS) example\n- `calculator.ts` — TypeScript example with proper types\n\n### Running Examples\n\n#### If you installed from npm:\n```sh\nnpm install @chatfinai/javascript-vm\n```\n\nThen update the import statements in the examples:\n- In `calculator.js`: Change `require('../dist/index.js')` to `require('@chatfinai/javascript-vm')`\n- In `calculator.ts`: Change `from '../src/index'` to `from '@chatfinai/javascript-vm'`\n\n```sh\n# Run JavaScript example\nnode examples/calculator.js\n\n# Run TypeScript example\nnpx ts-node examples/calculator.ts\n```\n\n#### If you're running from source:\n```sh\n# First, build the project\nnpm run build\n\n# Run JavaScript example (uses dist/index.js)\nnode examples/calculator.js\n\n# Run TypeScript example (uses src/index.ts)\nnpx ts-node examples/calculator.ts\n```\n\n## License\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Maintainers\n- ChatFinAI Open Source Team (<support@chatfin.ai>)\n\n## Support\nFor questions or support, open an issue on GitHub or contact us at <support@chatfin.ai>.\n","readmeFilename":"README.md"}