|
1 | 1 | ---
|
2 | 2 | layout: post
|
3 |
| -title: "Version 1.0.0 of the QuickJS sandbox released" |
4 |
| -date: YYYY-MM-DD hh:mm:ss -0000 |
| 3 | +title: "Announcing QuickJS 1.0.0 - Execute JavaScript in a WebAssembly QuickJS Sandbox" |
| 4 | +description: "Version 1.0 of the QuickJS package is released. A TypeScript package that allows you to safely execute JavaScript code within a WebAssembly sandbox using the QuickJS engine." |
| 5 | +date: 2024-07-07 12:00:00 |
5 | 6 | categories: release
|
6 | 7 | ---
|
7 | 8 |
|
8 |
| -Happy to announce |
| 9 | +## Announcing QuickJS 1.0.0 - Execute JavaScript in a WebAssembly QuickJS Sandbox |
| 10 | + |
| 11 | +We are excited to announce the release of **QuickJS 1.0.0**, a TypeScript package that allows you to safely execute JavaScript code within a WebAssembly sandbox using the QuickJS engine. Perfect for isolating and running untrusted code securely, QuickJS leverages the lightweight and fast QuickJS engine compiled to WebAssembly, providing a robust environment for code execution. |
| 12 | + |
| 13 | +### Key Features |
| 14 | + |
| 15 | +- **Security**: Run untrusted JavaScript code in a safe, isolated environment. |
| 16 | +- **File System**: Can mount a virtual file system. |
| 17 | +- **Custom Node Modules**: Custom node modules are mountable. |
| 18 | +- **Fetch Client**: Can provide a fetch client to make http(s) calls. |
| 19 | +- **Test-Runner**: Includes a test runner and chai-based `expect`. |
| 20 | +- **Performance**: Benefit from the lightweight and efficient QuickJS engine. |
| 21 | +- **Versatility**: Easily integrate with existing TypeScript projects. |
| 22 | +- **Simplicity**: User-friendly API for executing and managing JavaScript code in the sandbox. |
| 23 | + |
| 24 | +### Full Documentation and Examples |
| 25 | + |
| 26 | +- **[View the full documentation](https://sebastianwessel.github.io/quickjs/)** |
| 27 | +- **[Find examples in the repository](https://github.com/sebastianwessel/quickjs/tree/main/example)** |
| 28 | + |
| 29 | +### Basic Usage Example |
| 30 | + |
| 31 | +Here's a simple example of how to use the package: |
| 32 | + |
| 33 | +```typescript |
| 34 | +import { quickJS } from '@sebastianwessel/quickjs' |
| 35 | + |
| 36 | +// General setup like loading and init of the QuickJS wasm |
| 37 | +// It is a resource-intensive job and should be done only once if possible |
| 38 | +const { createRuntime } = await quickJS() |
| 39 | + |
| 40 | +// Create a runtime instance each time a js code should be executed |
| 41 | +const { evalCode } = await createRuntime({ |
| 42 | + allowFetch: true, // inject fetch and allow the code to fetch data |
| 43 | + allowFs: true, // mount a virtual file system and provide node:fs module |
| 44 | + env: { |
| 45 | + MY_ENV_VAR: 'env var value' |
| 46 | + }, |
| 47 | +}) |
| 48 | + |
| 49 | +const result = await evalCode(` |
| 50 | +import { join } as path from 'path' |
| 51 | +
|
| 52 | +const fn = async () => { |
| 53 | + console.log(join('src','dist')) // logs "src/dist" on host system |
| 54 | +
|
| 55 | + console.log(env.MY_ENV_VAR) // logs "env var value" on host system |
| 56 | +
|
| 57 | + const url = new URL('https://example.com') |
| 58 | +
|
| 59 | + const f = await fetch(url) |
| 60 | +
|
| 61 | + return f.text() |
| 62 | +} |
| 63 | +
|
| 64 | +export default await fn() |
| 65 | +`) |
| 66 | + |
| 67 | +console.log(result) // { ok: true, data: '<!doctype html>\n<html>\n[....]</html>\n' } |
| 68 | +``` |
| 69 | + |
| 70 | +### Credits |
| 71 | + |
| 72 | +This library is based on: |
| 73 | + |
| 74 | +- [quickjs-emscripten](https://github.com/justjake/quickjs-emscripten) |
| 75 | +- [quickjs-emscripten-sync](https://github.com/reearth/quickjs-emscripten-sync) |
| 76 | +- [memfs](https://github.com/streamich/memfs) |
| 77 | + |
| 78 | +Tools used: |
| 79 | + |
| 80 | +- [Bun](https://bun.sh) |
| 81 | +- [Biome](https://biomejs.dev) |
| 82 | +- [Hono](https://hono.dev) |
| 83 | +- [poolifier-web-worker](https://github.com/poolifier/poolifier-web-worker) |
| 84 | +- [tshy](https://github.com/isaacs/tshy) |
| 85 | +- [autocannon](https://github.com/mcollina/autocannon) |
| 86 | + |
| 87 | +### License |
| 88 | + |
| 89 | +This project is licensed under the MIT License. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +QuickJS 1.0.0 is ideal for developers looking to execute JavaScript code securely within a TypeScript application, ensuring both performance and safety with the QuickJS WebAssembly sandbox. Try it out and let us know what you think! |
| 94 | + |
| 95 | +[Check out QuickJS on GitHub](https://github.com/sebastianwessel/quickjs) |
0 commit comments