Introducing a new way to review your PRs.

Read the announcement

superradcompany / microsandbox

🧱 easy, fast, programmable and local-first microVM runtime and library

View on GitHub

27 documents · Updated Nov 23, 2026

docs / filesystem-backends

Filesystem backends and operations

The filesystem backends present guest file trees through one FUSE contract. MemFs keeps data in memory, PassthroughFs exposes a host directory, SingleFileFs exposes one selected host file, and DualFs joins two child trees into one view. Shared rules keep guest identity, metadata, limits, state movement, and host error behavior consistent. See the filesystem architecture page for mounts and sandbox roots.

Backend roles

MemFs

MemFs is an ephemeral file tree for data that must live only while the backend runs. It stores file data, names, metadata, links, special-file information, and guest xattrs without using a host directory.

It exposes separate limits for regular-file data and tracked inodes. The guest sees those limits through filesystem statistics. Cache and writeback choices control how the FUSE layer uses the in-memory tree.

References: crates/…/mod.rs• L1-6 crates/…/types.rs• L20-39 crates/…/builder.rs• L49-59

PassthroughFs

PassthroughFs maps one host directory into the guest namespace. Guest operations act on host objects while the backend keeps a separate guest inode and handle view. A read-only mount rejects guest mutations even when the host directory is writable.

Its policy controls root safety, stat virtualization, host permission changes, caching, the synthetic init.krun entry, guest-write quota, and state size. Strict stat virtualization checks the required xattr capability when the mount starts. Read-only mounts need read access. Writable mounts need write access. Relaxed mode uses the overlay when available. Off mode shows host metadata and rejects features that need virtual metadata.

The backend can use a bind identity map for guest ownership fallback. This map is valid only when stat virtualization is active. The optional no-symlink root policy resolves every root component without following symlinks or accepting .., which prevents a caller-controlled path from moving the mount outside its intended target.

Passthrough state can move between compatible instances. External state reopens and verifies the same host objects. Owned state carries a private namespace and its data. Both forms keep guest inode and handle state bounded and reject invalid or incompatible state before it changes the live backend.

The Unix backend also provides guarded runtime-script backing for a private runtime share. It can inspect a registered set of regular UTF-8 script files below a pinned runtime directory, preserve their guest metadata, and build a private temporary copy for later admission. This local staging is not a full filesystem restore and does not prove that unregistered files or handles are present.

References: crates/…/mod.rs• L63-189 crates/…/builder.rs• L38-53 crates/…/builder.rs• L162-250 crates/…/mod.rs• L1042-1184 crates/…/file_metadata.rs• L15-57 crates/…/runtime_scripts.rs• L108-269 crates/…/runtime_scripts.rs• L308-501 crates/…/mobility.rs• L147-329 crates/…/owned.rs• L40-77

SingleFileFs

SingleFileFs gives the guest an isolated directory with one selected host file under a guest-selected name. It hides the source file's parent and its siblings while reusing passthrough behavior for the selected object.

The view stays connected to the host path rather than making a copy. Its quota counts only the selected file. Existing handles keep their opened object when the host replaces the path. Checkpoint restore admits only the selected file and translates only its basename.

References: crates/…/mod.rs• L1-6 crates/…/mod.rs• L54-63 crates/…/mod.rs• L118-140 crates/…/mobility.rs• L21-29 crates/…/mobility.rs• L93-140

DualFs

DualFs presents two child backends as one guest filesystem. A policy decides which child supplies each read or write. The merged state records the child backing each guest object so a guest inode remains stable while an object changes source.

The default policy reads from backend B and writes to backend A. Other policies can use one child or merge both with a chosen precedence. A policy creates an operation plan. The core performs the I/O and commits the resulting namespace state.

Whiteouts hide names from one child. Opaque directories stop lower-child entries below a directory. When a write targets an object that exists only in the other child, materialization copies its data and guest-visible metadata into the write child before the operation continues.

References: crates/…/mod.rs• L1-5 crates/…/types.rs• L55-81 crates/…/types.rs• L166-207 crates/…/builder.rs• L116-145 crates/…/materialize.rs• L359-576

Shared backend machinery

All backends implement DynFileSystem, the FUSE-facing contract for names, data, directories, metadata, xattrs, and special operations. Shared support supplies stable directory views, guest-compatible names and errors, the synthetic init file, stat handling, inode maps, and bounded state framing.

The shared platform layer translates native host errors into Linux errno values. This keeps the guest contract stable when the backend runs on Linux, macOS, or Windows.

References: crates/…/lib.rs• L43-48 crates/…/mod.rs• L1-11 crates/…/mobility.rs• L20-77 crates/…/platform.rs• L1-18 crates/…/platform.rs• L221-235

Namespace and handle tracking

Guest inode identity

An inode is the stable guest identity of a file-system object. Memory backends assign synthetic identities. Passthrough maps a guest inode to host identity. SingleFileFs restricts that mapping to its selected object. DualFs maps one guest inode to one or both child inodes.

Passthrough lookup derives host identity from the opened object before it registers the guest inode. On Linux the identity includes the mount ID, so equal inode numbers from different mounts do not merge. Aliases preserve hard links and rename results. An anchor gives the backend a preferred safe path for reopening an object. If the anchor disappears, another admitted alias can repair it.

When the last namespace reference and lookup reference disappear, the backend removes the inode unless an open handle or an anchored child still needs it. An unlinked object can retain a host descriptor so existing handles continue to work. macOS uses its device-and-inode identity path for linked objects and a retained descriptor for detached objects.

References: crates/…/inode_table.rs• L20-103 crates/…/inode.rs• L215-328 crates/…/inode.rs• L541-674 crates/…/inode.rs• L874-984 crates/…/mod.rs• L50-64 crates/…/types.rs• L84-116

Open handles

An open handle is the live state of one guest open. It keeps the opened host object and guest flags. Passthrough tracks file handles by both handle ID and inode, so operations can find a usable descriptor for an inode without discarding another open handle.

The handle is authoritative for operations such as attribute reads after host replacement. This lets an unlinked or replaced file remain usable through an existing open. Directory handles keep a point-in-time entry list with stable offsets, so later reads can resume even after the namespace changes.

Passthrough checkpoint state records file handles, directory handles, and directory snapshots. Restore reopens destination-local objects and restores the guest IDs. A state that cannot safely reconnect an object is rejected or, for relaxed external restore, marks that inode unavailable instead of reusing its old identity.

References: crates/…/handle_table.rs• L11-69 crates/…/handle_table.rs• L1-17 crates/…/metadata.rs• L34-48 crates/…/metadata.rs• L96-133 crates/…/dir_snapshot.rs• L30-106 crates/…/mobility.rs• L69-141 crates/…/unavailable.rs• L11-64

Directory views

Directory reads use a lazy snapshot for each open directory handle. The snapshot gives names and offsets a stable order for that handle. Passthrough readdirplus records lookup references only for entries that it emits.

If an entry disappears after the snapshot, the backend skips that name. Other lookup failures do not turn an existing name into an unowned inode. This keeps a temporary host error from silently changing the guest directory view.

References: crates/…/dir_snapshot.rs• L30-40 crates/…/dir_snapshot.rs• L73-106 crates/…/dir_ops.rs• L145-229

Metadata and file types

Metadata views

Metadata gives the guest ownership, permissions, file type, device identity, size, and time values. MemFs owns those values in its in-memory nodes. Passthrough combines host size and time values with a guest metadata view.

On Unix, stat virtualization stores guest uid, gid, mode, and device values in an internal override xattr. Host ownership does not need to change. Guest access checks use the guest-visible values. The independent host-permission policy can mirror ordinary permission bits for regular files and directories while keeping an owner-access floor for the host process.

Mode, owner, and privilege-clearing changes update the guest overlay when it is enabled. Size and time changes act on the host object. When the overlay is off, chmod acts on the host mode and guest owner changes are rejected because the host process cannot honestly apply them.

References: crates/…/metadata.rs• L33-71 crates/…/metadata.rs• L135-217 crates/…/metadata.rs• L285-331 crates/…/mod.rs• L94-114 crates/…/stat_override.rs• L67-197 crates/…/types.rs• L73-100

On Windows, the backend builds a guest stat view from host size and time data plus virtual ownership, mode, device, and type data. A configured default owner supplies ownership for host-created files without an override. This setting requires stat virtualization.

Stat virtualization has three modes. Strict requires the metadata store at mount time. Relaxed uses it when available. Off exposes host metadata. The selected mode controls whether guest ownership changes and virtual special-file types are available.

References: crates/…/builder.rs• L9-20 crates/…/builder.rs• L88-95 crates/…/mod.rs• L448-489

Extended attributes

Extended attributes, or xattrs, are named byte values attached to file-system objects. MemFs stores them as guest data. Unix PassthroughFs passes guest xattrs to the host while hiding the internal stat-override xattr. Windows has no guest xattr interface in this backend.

The override value is versioned binary metadata for guest uid, gid, mode, and device data. A missing value leaves host metadata in place or uses the bind identity map. A corrupt value fails with EIO instead of exposing an unknown stat view.

The hidden override key is blocked from guest get, set, and remove operations. It is also removed from list results. A size-only list query counts the filtered result, so it does not reveal that the internal key exists. Xattr operations use an existing open handle when possible and otherwise open the tracked inode.

References: crates/…/xattr_ops.rs• L1-13 crates/…/xattr_ops.rs• L34-172 crates/…/xattr_ops.rs• L175-280 crates/…/xattr_ops.rs• L283-377 crates/…/stat_override.rs• L1-18 crates/…/stat_override.rs• L126-197

Special files

The backends recognize regular files, directories, symbolic links, FIFOs, sockets, and block or character devices. MemFs represents these types directly. Unix passthrough uses host objects where it can and uses virtual metadata for types that the unprivileged host process cannot create.

On Unix mknod creates a host regular file for virtual special types and stores the guest type and device value in the override. Without stat virtualization, only a real regular file is supported. Linux strict mode stores guest-created symlinks as regular files with the target as content and a virtual symlink type. Linux relaxed and off modes use real symlinks. macOS uses real symlinks and can store their override metadata.

init.krun is a synthetic read-only entry backed by embedded agent bytes. It cannot be changed, linked, or given xattrs. It does not represent an ordinary host namespace object.

References: crates/…/create_ops.rs• L225-301 crates/…/create_ops.rs• L304-434 crates/…/create_ops.rs• L505-580 crates/…/init_binary.rs• L1-20 crates/…/types.rs• L103-128 crates/…/tests.rs• L832-904

Quotas and capacity

MemFs capacity

MemFs limits regular-file bytes and inode count separately. Growth reserves byte capacity before data changes. Shrinking and removal release capacity. The guest sees the remaining byte and inode budget through statfs.

The byte limit measures logical file data. It covers truncate extension and allocation. Hole punching clears data without changing file size and does not charge new space.

References: crates/…/inode.rs• L31-42 crates/…/inode.rs• L155-200 crates/…/metadata.rs• L51-80 crates/…/special.rs• L32-181

Passthrough guest-write quota

A passthrough quota limits guest-attributable growth in a host subtree. Existing host data becomes the baseline when the first write-intent operation occurs. The guest pays only for growth beyond that baseline. A single-file view uses the selected file as its accounting root even though it resolves names through the parent directory.

The backend charges writes, extending truncates, allocation, and host-side copy growth before the host mutation. It uses logical file size, so sparse files count by their apparent size. When the fast estimate reaches the limit, it recounts the subtree. A rejected growth returns ENOSPC, and statfs reports the baseline plus the guest budget with the remaining budget as available space.

References: crates/…/mod.rs• L513-528 crates/…/quota.rs• L1-41 crates/…/quota.rs• L119-151 crates/…/quota.rs• L185-267 crates/…/mod.rs• L118-123

Operation flows

FUSE operation flow

Each guest request enters through the same operation contract. The backend resolves the guest identity, applies its policy, performs memory or host work, updates tracked state, and returns guest-shaped data or a Linux errno.

The following flow shows how the common contract reaches each backend family.

flowchart LR
    G[Guest file operation] --> F[FUSE DynFileSystem contract]
    F --> R[Resolve inode or name]
    R --> P{Backend policy}
    P --> M[MemFs memory tree]
    P --> H[PassthroughFs host tree]
    P --> S[SingleFileFs selected file]
    P --> D[DualFs merged namespace]
    M --> O[Guest result or Linux errno]
    H --> O
    S --> O
    D --> O

DualFs adds hook stages around resolution, planning, dispatch, and state commit. Hooks can deny an operation, add policy input, return a synthetic result, or observe the dispatch without changing it.

References: crates/…/lib.rs• L43-48 crates/…/hooks.rs• L19-60 crates/…/policy.rs• L15-25 crates/…/mod.rs• L289-323

DualFs materialization flow

Materialization makes an object present in the write child when a DualFs policy must change an object found in the other child. It preserves the guest inode while the target object is created and the backing record changes.

The transition keeps the source available until the target is ready.

sequenceDiagram
    participant G as Guest
    participant D as DualFs
    participant S as Source child
    participant T as Write child
    G->>D: Mutation or writable open
    D->>D: Select target and lock transition
    D->>T: Create target ancestors
    D->>S: Read data and guest metadata
    D->>T: Create object and copy data
    D->>T: Copy xattrs and metadata
    D->>D: Commit target backing state
    D-->>G: Continue operation

Regular files move in chunks. Links and special files are recreated from their type-specific data. This preserves a continuous guest view during the child transition.

References: crates/…/materialize.rs• L17-25 crates/…/materialize.rs• L76-125 crates/…/materialize.rs• L359-576

Passthrough checkpoint flow

Passthrough checkpointing separates live backend state from the host objects or private data that state refers to. Capture records guest inodes, handles, directory snapshots, quotas, and the selected checkpoint kind. Restore validates the shape and compatibility before reopening or materializing objects.

The following flow shows the common boundary between capture, verification, and restore.

flowchart LR
    A[Quiesced PassthroughFs] --> C[Capture state and backing identity]
    C --> V[Bounded verified state]
    V --> E[Reopen external host objects]
    V --> M[Materialize owned private tree]
    E --> R[Restored PassthroughFs]
    M --> R

External restore checks object identity, type, metadata, and content fingerprints. Strict restore rejects a changed object. Relaxed restore removes the changed inode from restored state and marks the old guest identity unavailable. Owned generations preserve linked objects, symlinks, detached handles, and per-object metadata in a private destination.

State framing includes a backend kind, schema, and size limit. Malformed lengths, trailing bytes, unsupported kinds, and over-limit state fail before restore can allocate untrusted state.

References: crates/…/mobility.rs• L147-329 crates/…/mobility.rs• L393-436 crates/…/owned.rs• L79-173 crates/…/owned.rs• L176-362 crates/…/mobility.rs• L12-129

Platform operations

DAX mappings

Direct access, or DAX, maps a file range into shared memory so the guest can use file data without ordinary read and write requests. The backend validates the range and access mode, keeps the host backing alive, and removes the mapping when the guest releases it.

Writable DAX is not admitted because the mapping does not carry a sufficient open-handle identity. Read-only mounts and the synthetic init file are checked before a mapping is created. Unix and Windows use different host mapping mechanisms but keep the same guest lifecycle.

References: crates/…/dax.rs• L1-81 crates/…/dax.rs• L84-195 crates/…/ops.rs• L600-640

Unix host operations

Unix passthrough resolves names relative to pinned descriptors inside the exported root. The no-symlink root policy checks every root component. Linux uses openat2 containment when available and a component walk otherwise. Native errors become Linux errno values before they cross the FUSE boundary.

Special operations use the guest-supplied handle. Sync flushes host state. Seek preserves Linux SEEK_DATA and SEEK_HOLE behavior across Unix hosts. Filesystem statistics show the configured guest quota when one is active. Growth is charged before host allocation or copying.

Guest open flags are Linux values even on macOS, so the backend translates them before host calls. Linux can use host-side range copy and allocation. macOS reports unsupported range copy or allocation modes through the matching Linux fallback errno so the guest can choose another path.

References: crates/…/inode.rs• L70-150 crates/…/inode.rs• L765-811 crates/…/special.rs• L1-224 crates/…/special.rs• L259-329 crates/…/platform.rs• L12-18 crates/…/platform.rs• L602-633

Windows host operations

Windows passthrough maps the guest tree to a host directory while rejecting unsafe reparse points and path components. Its virtual metadata store supplies guest ownership, mode, device, and special-file type values that Windows host metadata does not provide.

Directory enumeration omits unsafe reparse points but keeps safe siblings and usable offsets. The metadata store uses an alternate data stream when available and a reserved sidecar directory as a fallback. Strict mode requires a working store. Relaxed mode can continue without it. Off mode disables virtual metadata.

Windows DAX uses host file views and a VMM mapping. It maps existing bytes, refreshes surviving mappings after growth, and releases views before operations that require host resize. The host view remains alive until the guest mapping is removed.

References: crates/…/mod.rs• L287-384 crates/…/dir_ops.rs• L49-119 crates/…/stat_store.rs• L11-147 crates/…/dax.rs• L130-261 crates/…/memory_mapping.rs• L123-238

Change checklist

When these files or sections are changed, remember to consider these:

  • A new FUSE operation must have matching behavior in each relevant child backend, DualFs routing, SingleFileFs admission, handle state, hooks, and synthetic-entry rules.
  • A metadata change must stay aligned across the in-memory view, Unix override xattr, Windows metadata store, bind identity map, DualFs materialization, owned-generation metadata, and runtime-script staging.
  • A growth path must charge quota or memory capacity before mutation. Review write, truncate extension, allocation, and host-side copy together.
  • A namespace change must update guest inode aliases, host identity maps, open-handle lifetime, directory snapshots, whiteouts, opaque directories, and checkpoint state as needed.
  • A passthrough state change must keep inode paths, host identity checks, handle flags, directory cookies, quota state, and bounded framing consistent.
  • Create and link changes must preserve the opened object's identity when a host rename or replacement occurs between creation and inode registration.
  • Stat virtualization changes must preserve separate strict read and write probes. Do not alter the persisted mount-root metadata during a capability probe.
  • Xattr changes must keep the internal override key hidden in both list results and size-only queries. They must keep handle reuse safe when one of several handles closes.
  • Root-safety changes must keep Unix symlink checks, Windows reparse checks, .. rejection, component validation, and directory filtering aligned.
  • Platform operations must preserve Linux errno results and define a guest fallback when the host lacks an operation.
  • DAX changes must keep range checks, read-only admission, host backing lifetime, VMM acknowledgement, growth refresh, and mapping removal aligned.
  • Runtime-script capture and staging changes must keep pinned-source checks, exact guest metadata, name and size limits, private temporary output, and late-failure cleanup aligned. They must not be treated as full state restore.
  • Relaxed external restore changes must keep malformed state rejected and must not reuse an invalidated guest inode when its path later reappears.

Important failure modes

TriggerConsequenceGuard
MemFs reaches its byte or inode limitCreate, write, truncate, or allocation returns ENOSPC before the limit is exceeded.Reserve bytes and inodes before changing memory state.
Strict passthrough stat virtualization lacks required xattr accessMount creation fails instead of exposing an incomplete guest metadata model.Probe read access for read-only mounts and write access for writable mounts.
A bind identity map is used with stat virtualization offBackend construction rejects the configuration because the map has no effect.Validate the policy combination during construction.
A guest growth request crosses a passthrough quotaThe host file is not grown and the guest receives ENOSPC.Charge write, truncate extension, allocation, and copy growth first.
A host object changes during external checkpoint restoreStrict restore fails. Relaxed restore marks the old inode unavailable.Compare the saved identity and recheck the destination object before installing state.
A host rename replaces a name during create registrationA returned entry or handle could refer to the replacement instead of the opened object.Register the inode from the descriptor returned by create.
A guest reads or lists the stat-override xattrGuest metadata storage is exposed or its existence leaks.Reject direct access and filter the key from full and size-only listings.
A Unix root path contains a symlink under no-symlink policyMount creation fails rather than following the path to another target.Resolve from a trusted base without following any component or accepting ...
A Windows directory contains a reparse pointDirect lookup returns ELOOP and listing omits the unsafe entry.Apply the reparse guard per entry and retain safe sibling offsets.
A runtime script is linked, replaced, changed, or not a regular UTF-8 fileCapture or staging fails without publishing a partial private runtime tree.Pin the source, compare identity, bytes, and guest metadata, reject links, and use bounded temporary staging.
Runtime-script input exceeds trusted bounds or uses an unsafe nameNo staged files are created and the caller receives a redacted backing or limit error.Validate all names and limits before creation, then reopen and verify staged files.
A writable DAX request lacks a safe handle identityThe mapping could bypass normal access control.Admit only supported read-only mappings before installing the shared view.

Key files

FileWhy to read it
crates/…/lib.rsDefines the guest-facing filesystem contract.
crates/…/mobility.rsDefines bounded state framing and compatibility checks.
crates/…/mod.rsShows the in-memory backend role and operation surface.
crates/…/types.rsDefines in-memory nodes, metadata, content, and handles.
crates/…/special.rsDefines capacity reporting and in-memory special operations.
crates/…/mod.rsDefines Unix passthrough policies, state, root safety, and FUSE mapping.
crates/…/builder.rsShows construction checks, capability probes, quotas, and state limits.
crates/…/inode.rsExplains host identity, aliases, detached objects, and safe reopening.
crates/…/handle_table.rsShows the dual handle indexes used for open-object lookup.
crates/…/create_ops.rsExplains creation, special-file virtualization, symlink policy, and identity-safe registration.
crates/…/file_metadata.rsDefines strict runtime-backing metadata reads and guest permission seeding.
crates/…/runtime_scripts.rsDefines bounded runtime-script observation, exact staging, and restored backing.
crates/…/runtime_scripts_tests.rsDemonstrates race, namespace, metadata, cleanup, and handle-restoration guarantees for runtime backing.
crates/…/metadata.rsShows the guest metadata view and access checks.
crates/…/xattr_ops.rsShows guest xattr behavior and internal-key filtering.
crates/…/dir_ops.rsExplains stable directory snapshots and lookup references.
crates/…/special.rsDefines Unix sync, seek, allocation, copy, and quota-visible statistics.
crates/…/mobility.rsDefines Unix inode, handle, quota, and external checkpoint movement.
crates/…/owned.rsDefines owned generations and private namespace materialization.
crates/…/quota.rsDefines guest-growth accounting and quota-visible space.
crates/…/mod.rsExplains the isolated one-file namespace and quota root.
crates/…/types.rsDefines merged namespace state and child backing records.
crates/…/materialize.rsShows cross-child object materialization.
crates/…/inode_table.rsExplains guest inode identity and host aliases.
crates/…/stat_override.rsDefines virtual metadata and identity mapping.
crates/…/stat_store.rsExplains Windows metadata persistence and fallback.
crates/…/dax.rsShows the Windows DAX lifecycle.
crates/…/platform.rsDefines path containment and cross-platform errno behavior.
crates/…/mod.rsDefines the end-to-end Unix passthrough test harness and guest errno expectations.
crates/…/test_create_ops.rsCovers creation, symlinks, special files, hard links, and handle identity.
crates/…/test_file_ops.rsCovers open handles, read/write behavior, release, and host error reporting.
crates/…/test_quota.rsCovers baseline accounting, growth limits, reclamation, and statfs.
crates/…/test_xattr_ops.rsCovers guest xattrs, hidden override metadata, and size-query filtering.