sandboxedjs 0.1.2 → 0.1.4
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 +42 -5
- package/dist/index.cjs +4896 -211
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4895 -211
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -45,6 +45,7 @@ Node 18.17+. Everything is pure JavaScript and WebAssembly — no compilation st
|
|
|
45
45
|
| **Coreutils** | 154 programs — `ls cat cp mv rm mkdir grep sed awk find head tail sort uniq wc cut tr tee xargs chmod chown ln du df ps tar gzip base64 sha256sum diff curl wget` and the rest — plus 54 shell builtins |
|
|
46
46
|
| **Node.js** | Real Node semantics via Nodepod — `require`, npm packages, `http`, `fs`, streams, `worker_threads` |
|
|
47
47
|
| **Python** | MicroPython on WebAssembly, mounted on the *same* filesystem |
|
|
48
|
+
| **FFmpeg** | `ffmpeg` and `ffprobe` (FFmpeg 5.1) reading and writing container files directly — [optional install](#video-and-audio) |
|
|
48
49
|
| **`/proc`** | Live and synthesised — `ps`, `top`, `free` and `uptime` all read the same source |
|
|
49
50
|
| **Networking** | Virtual interfaces, `/etc/hosts` resolution, in-container HTTP servers, an optional bridge to a real host port |
|
|
50
51
|
| **Users** | Real `/etc/passwd` and `/etc/group`; `useradd`, `su`, `sudo`, and permission checks that deny for real — for the shell and Python, [but not Node](#the-in-container-user-model-does-not-constrain-nodejs) |
|
|
@@ -587,15 +588,51 @@ Those three use dynamic imports, so they only fail if you call them.
|
|
|
587
588
|
removed and the seam is there, but treat browser support as "should work, unproven" rather than
|
|
588
589
|
a tested claim.
|
|
589
590
|
|
|
591
|
+
## Video and audio
|
|
592
|
+
|
|
593
|
+
`ffmpeg` and `ffprobe` are FFmpeg 5.1 compiled to WebAssembly, mounted on the container's own
|
|
594
|
+
filesystem. The mount is the point: inputs and outputs are ordinary container files, so nothing
|
|
595
|
+
is staged in or copied back and a pipeline can be built out of scripts and pipes as usual.
|
|
596
|
+
|
|
597
|
+
The runtime is ~31MB of WebAssembly, which is a lot to force on someone who wants a shell, so it
|
|
598
|
+
installs separately. Without it the commands report themselves as missing, exactly as a real
|
|
599
|
+
system reports an uninstalled binary:
|
|
600
|
+
|
|
601
|
+
```bash
|
|
602
|
+
npm install @ffmpeg/core
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
```js
|
|
606
|
+
const box = await createContainer({ cwd: "/media" });
|
|
607
|
+
|
|
608
|
+
// Make a clip, then transcode it — both files are just container files.
|
|
609
|
+
await box.exec("ffmpeg -f lavfi -i testsrc=size=640x480:rate=25:duration=5 -pix_fmt yuv420p clip.mp4");
|
|
610
|
+
await box.exec("ffmpeg -i clip.mp4 -vf scale=320:-2 -frames:v 1 thumb.png");
|
|
611
|
+
|
|
612
|
+
const thumbnail = await box.fs.readFile("/media/thumb.png");
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
Every FFmpeg invocation gets a fresh WebAssembly instance, because FFmpeg ends by calling
|
|
616
|
+
`exit()` and tears its runtime down as it goes; the compiled module is cached, so only the cheap
|
|
617
|
+
half is repeated. Runs are synchronous — a long transcode occupies the thread until it finishes.
|
|
618
|
+
|
|
619
|
+
Two caveats worth knowing:
|
|
620
|
+
|
|
621
|
+
- **`ffprobe` does not report an exit status.** Whenever it does real work this build leaves
|
|
622
|
+
through `exit()` without setting a return value, so success and failure are indistinguishable
|
|
623
|
+
to the caller. It is reported as success; branch on its *output*, not its exit code. `ffmpeg`
|
|
624
|
+
itself reports status correctly and can be relied on in `&&` chains.
|
|
625
|
+
- **No hardware acceleration and no native codecs** beyond what the WebAssembly build ships.
|
|
626
|
+
|
|
590
627
|
## Known limits
|
|
591
628
|
|
|
592
629
|
Honest list of what does not work:
|
|
593
630
|
|
|
594
|
-
- **
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
631
|
+
- **esbuild-based toolchains.** Nodepod boots esbuild by importing it from a CDN over `https:`,
|
|
632
|
+
which the Node ESM loader refuses, so anything routed through esbuild cannot start under Node.
|
|
633
|
+
This affects older toolchains — Vite 4 and its contemporaries. Current Vite ships its Rust
|
|
634
|
+
pipeline as WebAssembly and runs fine, dev server included, as do Express, Koa, Fastify-style
|
|
635
|
+
apps and plain `http` servers.
|
|
599
636
|
- **Python is MicroPython**, so C extensions (`numpy`, `pandas`, `cryptography`) are unavailable.
|
|
600
637
|
- **No real sockets.** HTTP servers work through the request proxy; raw TCP/UDP does not.
|
|
601
638
|
- **No real processes.** Processes are cooperative async tasks: `kill -9` cannot interrupt a
|