I'd like to use wasmtime (more specifically, wasm_bridge, which is built on top of wasmtime) to add plugin support to one of my projects. It's got a custom virtual filesystem, which I'd like to use to back a custom WASI implementation.
How would I go about doing this?
This topic was moved here from #general > Writing & Using a custom WASI implementation with wasmtime by fitzgen (he/him).
The general answer is that this is not well supported. The implementation of wasmtime-wasi
routes filesystem things to the host filesystem. Implementing your own custom virtual filesystem would require you to not use wasmtime-wasi
and supply the host imports yourself, which is likely a larger undertaking than what you're looking to bite off
So, what should I do?
Have you seen https://github.com/bytecodealliance/WASI-Virt ? It htink the goals might be somewhat similar and it might spark some inspiration!
Hmm, this is definitely useful as a reference, I think!
One of my goals though is running plugins in the browser, as my project also currently supports running in the browser (hence why I'm using wasm_bridge, which uses wasmtime on native and browser APIs on wasm) and WASI-Virt doesn't seem to align with that goal.
This is also one of my motivating reasons for writing a custom WASI implementation- my project uses the FileSystem Access API, which directly modifies the user's filesystem- so I could get plugins that interact with files to work even on the web!
Ah so in that case, you're going to want to also glance at jco
as well: https://github.com/bytecodealliance/jco , just in case you haven't seen it already!
Alex Crichton said:
Implementing your own custom virtual filesystem would require you to not use
wasmtime-wasi
and supply the host imports yourself, which is likely a larger undertaking than what you're looking to bite off
How large of an undertaking are we talking?
the implementation of the filesystem that uses cap-std to implement a bunch of the hard parts (sandboxing access underneath a directory via openat2(2)) is around 1500loc between https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi/src/host/filesystem.rs and https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasi/src/filesystem.rs
implementing a custom filesystem that is read-only and lacks symlinks/hardlinks is probably a day or two of work. the rest of that is quite a bit of complexity
Last updated: Nov 22 2024 at 16:03 UTC