https://github.com/sebastianwessel/quickjs Skip to content Navigation Menu Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + GitHub Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions By size + Enterprise + Teams + Startups By industry + Healthcare + Financial services + Manufacturing By use case + CI/CD & Automation + DevOps + DevSecOps * Resources Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Enterprise + Enterprise platform AI-powered developer platform Available add-ons + Advanced Security Enterprise-grade security features + GitHub Copilot Enterprise-grade AI features + Premium Support Enterprise-grade 24/7 support * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} sebastianwessel / quickjs Public * Notifications You must be signed in to change notification settings * Fork 2 * Star 132 A typescript package to execute javascript code in a webassembly quickjs sandbox sebastianwessel.github.io/quickjs/ License MIT license 132 stars 2 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings * Code * Issues 3 * Pull requests 2 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights sebastianwessel/quickjs This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main BranchesTags Go to file Code Folders and files Name Name Last commit Last commit message date Latest commit History 21 Commits .vscode .vscode .zed .zed docs docs example example src src vendor/testrunner vendor/ testrunner .gitignore .gitignore .npmignore .npmignore LICENSE LICENSE README.md README.md biome.json biome.json bun.lockb bun.lockb jsr.json jsr.json loadtest.ts loadtest.ts package.json package.json play.ts play.ts test.ts test.ts tsconfig.json tsconfig.json vendor.ts vendor.ts View all files Repository files navigation * README * MIT license QuickJS - Execute JavaScript in a WebAssembly QuickJS Sandbox This TypeScript package allows you to safely execute JavaScript code within a WebAssembly sandbox using the QuickJS engine. Perfect for isolating and running untrusted code securely, it leverages the lightweight and fast QuickJS engine compiled to WebAssembly, providing a robust environment for code execution. Features * Security: Run untrusted JavaScript code in a safe, isolated environment. * File System: Can mount a virtual file system * Custom Node Modules: Custom node modules are mountable * Fetch Client: Can provide a fetch client to make http(s) calls * Test-Runner: Includes a test runner and chai based expect * Performance: Benefit from the lightweight and efficient QuickJS engine. * Versatility: Easily integrate with existing TypeScript projects. * Simplicity: User-friendly API for executing and managing JavaScript code in the sandbox. View the full documentation Find examples in the repository Basic Usage Here's a simple example of how to use the package: import { quickJS } from '@sebastianwessel/quickjs' // General setup like loading and init of the QuickJS wasm // It is a ressource intensive job and should be done only once if possible const { createRuntime } = await quickJS() // Create a runtime instance each time a js code should be executed const { evalCode } = await createRuntime({ allowFetch: true, // inject fetch and allow the code to fetch data allowFs: true, // mount a virtual file system and provide node:fs module env: { MY_ENV_VAR: 'env var value' }, }) const result = await evalCode(` import { join } as path from 'path' const fn = async ()=>{ console.log(join('src','dist')) // logs "src/dist" on host system console.log(env.MY_ENV_VAR) // logs "env var value" on host system const url = new URL('https://example.com') const f = await fetch(url) return f.text() } export default await fn() `) console.log(result) // { ok: true, data: '\n\n[....]\n' } Credits This lib is based on: * quickjs-emscripten * quickjs-emscripten-sync * memfs * Chai Tools used: * Bun * Biome * Hono * poolifier-web-worker * tshy * autocannon License This project is licensed under the MIT License. --------------------------------------------------------------------- This package is ideal for developers looking to execute JavaScript code securely within a TypeScript application, ensuring both performance and safety with the QuickJS WebAssembly sandbox. About A typescript package to execute javascript code in a webassembly quickjs sandbox sebastianwessel.github.io/quickjs/ Topics javascript package typescript module worker example sandbox webassembly wasm worker-pool worker-threads sandbox-environment quickjs quickjs-runtime quickjs-emscripten Resources Readme License MIT license Activity Stars 132 stars Watchers 1 watching Forks 2 forks Report repository Releases 1 Version 1.0 Latest Jul 7, 2024 Languages * TypeScript 86.5% * JavaScript 13.5% Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.