Skip to content

feat(wasm): host-backed filesystem for the wasm bindings - #2275

Merged
chaliy merged 3 commits into
mainfrom
codex/host-backed-filesystem
Aug 6, 2026
Merged

feat(wasm): host-backed filesystem for the wasm bindings#2275
chaliy merged 3 commits into
mainfrom
codex/host-backed-filesystem

Conversation

@chaliy

@chaliy chaliy commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What changed

new Bash({ fs }) in the wasm bindings now runs scripts directly against embedder-owned storage such as a Durable Object, IndexedDB, or OPFS. Reads and writes stay live; no workspace copy or write-back diff is required.

Hosts implement seven required raw-storage methods, validated at construction. PosixFs supplies parent, directory, and symlink semantics. Optional append/copy/rename operations have fallbacks, host POSIX error codes map to matching I/O kinds, and malformed host responses fail explicitly.

The async contract is enforced: host-backed filesystems require execute(), and files cannot be combined with fs.

Why

Embedders previously had to copy their storage into the in-memory VFS before every run and diff it back afterward. That was O(workspace), text-oriented, and exposed a lost-update window. The new adapter lets Bashkit operate on the embedder's authoritative bytes.

Before / After

Before: scripts only saw Bashkit's in-memory VFS; external storage required seeding and write-back.

After:

const bash = new Bash({ cwd: "/workspace", fs: myHost });
const result = await bash.execute("grep -rl TODO . | head -5");

The wasm integration suite proves redirects, reads, text tools, directories, copy/move fallbacks, error mapping, invalid host responses, async suspension, and constructor validation against an always-async fake host.

tests 63
pass 63
fail 0

Risk

  • Low: the path is additive and unreachable unless fs is supplied.
  • Host implementations with invalid metadata or directory-entry shapes now fail clearly.
  • Hosts without symlink methods receive ENOSYS for symlink operations.
  • Host-backed bytes are outside in-memory VFS quotas; this opt-in boundary is documented as TM-FS-017.

Checklist

  • Tests added or updated
  • Backward compatibility considered

chaliy added 3 commits August 6, 2026 00:21
`new Bash({ fs })` runs scripts directly against storage the embedder
owns — a Durable Object, OPFS, IndexedDB — instead of the in-memory VFS.
Nothing is copied in or diffed back out: every read and write during a
run is a call into the host object, so there is no workspace-size ceiling
beyond the host's own and no lost-update window between runs.

The bridge implements `FsBackend` and wraps it in `PosixFs`, so hosts
supply raw storage (seven required methods, validated at construction)
and inherit POSIX semantics. `append`, `copy`, and `rename` are
synthesized when omitted, `chmod` is accepted and ignored so `chmod +x`
works against hosts with no permission model, and host errors carrying a
`code` map onto the matching `io::ErrorKind` so builtins that branch on
kind behave as they do over the built-in VFS.

Host calls may return promises, so a host filesystem implies `execute()`;
`executeSync` reports the suspension rather than blocking, and `files` is
rejected alongside `fs` because seeding cannot complete synchronously.
A host that answers `undefined` is broken, and reading that as
"missing" turns every existence probe into a silent miss — a redirect
reports the workspace as gone rather than reporting the host. Fail
with a message that names the contract instead.

Also documents the host filesystem as TM-FS-017: it widens the sandbox
to whatever the embedder's object exposes, and its bytes live outside
the VFS quotas, so scoping and storage limits are the embedder's.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 70e9d47 Commit Preview URL

Branch Preview URL
Aug 06 2026, 05:39 AM

@chaliy
chaliy merged commit 33dbaa0 into main Aug 6, 2026
45 checks passed
@chaliy
chaliy deleted the codex/host-backed-filesystem branch August 6, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant