sb.fs(). Every op dispatches through the same host-guest channel as command execution, so there is no SSH and no network involved. Path-style helpers are the usual choice; handle-style helpers are available for callers that need POSIX-like file descriptor reuse. For bulk file movement, prefer a volume that gives the guest direct filesystem access. See Filesystem for conceptual usage.
Typical flow
sb.fs() is synchronous and just borrows the sandbox’s backend and name; the work happens on the awaited methods below, every one of which is async.
Read operations
fs.read()
Example
Example
Parameters
path&str“/app/config.json”.Returns
fs.read_to_string()
Example
Example
Parameters
path&strReturns
fs.read_stream()
Example
Example
Parameters
path&strReturns
Write operations
fs.write()
Example
Example
Parameters
path&strdataimpl AsRef<[u8]>fs.write_stream()
Example
Example
FsWriteSink::close() to flush and finalize. The file is created if missing and truncated if it exists.
Parameters
path&strReturns
Handle operations
Handle operations expose agentd-side file and directory handles. Use them when you need repeated reads/writes against the same open file, directory iteration state, or handle-based metadata updates. They requireSandbox::fs() on a live local sandbox because agentd scopes handles to the relay client; SandboxFsOps::with_backend() can run path-style methods but returns Unsupported for handle methods.
Example
Example
fs.open_file()
FsOpenOptions.
fs.open_dir()
read_dir_handle().
fs.close_handle()
fs.read_handle()
offset. Passing None for len reads through EOF.
fs.read_handle_stream()
read_handle().
fs.write_handle()
offset.
fs.write_handle_stream()
offset. Call FsWriteSink::close() to send EOF and wait for the guest to confirm the write.
fs.read_dir_handle()
limit caps the batch size when set.
fs.read_dir()
read_dir_handle().
fs.stat_handle()
fs.fstat()
stat_handle().
fs.set_stat_handle()
FsSetAttrs are changed.
fs.fset_stat()
set_stat_handle().
Directory operations
fs.list()
Example
Example
Parameters
path&strReturns
fs.mkdir()
Example
Example
Parameters
path&strfs.remove_dir()
Example
Example
remove().
Parameters
path&strfs.remove_empty_dir()
Example
Example
remove_dir(), this does not remove child entries and fails when the directory is not empty.
Parameters
path&strFile operations
fs.remove()
Example
Example
remove_dir() for directories.
Parameters
path&strfs.copy()
Example
Example
Parameters
from&strto&strfs.rename()
Example
Example
Parameters
from&strto&strMetadata
fs.stat()
Example
Example
stat_with_follow(path, true)); use stat_with_follow() to control that.
Parameters
path&strReturns
fs.stat_with_follow()
Example
Example
follow_symlink = false you stat the link itself rather than its target.
Parameters
path&strfollow_symlinkboolfalse, stat the symlink itself instead of its target.Returns
fs.set_stat()
Example
Example
FsSetAttrs are applied.
Parameters
path&strfollow_symlinkboolfalse, target the symlink itself instead of its target.attrsFsSetAttrsfs.read_link()
Example
Example
Parameters
path&strReturns
fs.symlink()
Example
Example
link_path that points to target.
Parameters
target&strlink_path&strfs.real_path()
Example
Example
Parameters
path&strReturns
fs.exists()
Example
Example
stat() probe: a successful stat yields true, a filesystem-op error yields false, and transport errors still propagate.
Parameters
path&strReturns
true if the path exists.Host transfer
fs.copy_from_host()
Example
Example
Parameters
host_pathimpl AsRef<Path>guest_path&strfs.copy_to_host()
Example
Example
Parameters
guest_path&strhost_pathimpl AsRef<Path>Types
SandboxFsOps
Returned by sb.fs()
Filesystem operations handle for a running sandbox, borrowing the parent sandbox’s backend and name (it is generic over a lifetime,SandboxFsOps<'a>). Every method dispatches through the same host-guest channel as command execution: core.fs.* agent messages over the relay socket locally, or the agent WebSocket route on cloud. Handle-based helpers (stat_handle and friends) require the live local agent client and return Unsupported on cloud. All operations are listed in the sections above.
with_backend(backend, name) is a public constructor for FFI shims that re-assemble a SandboxFsOps per call; most callers obtain one via sb.fs().
FsEntry
Returned by list()
Metadata for a single entry returned from a directory listing.FsEntryKind
Used by FsEntry.kind · FsMetadata.kind
The kind of a filesystem entry. DerivesCopy, PartialEq, and Eq.
FsMetadata
Returned by stat() · stat_with_follow()
Detailed metadata for a file or directory.FsOpenOptions
Used by open_file()
Options accepted byopen_file(). Re-exported from microsandbox_protocol::fs. Derives Default, so set only the flags you need.
FsSetAttrs
Used by set_stat() · set_stat_handle() · fset_stat()
Attributes accepted byset_stat(). Re-exported from microsandbox_protocol::fs. Derives Default, so set only the fields you want to change and spread the rest with ..Default::default(). Each field is Option: None leaves that attribute unchanged.
FsReadStream
Returned by read_stream() · read_handle_stream()
Streaming reader for file data from the sandbox. Obtained viaread_stream() or read_handle_stream().
FsWriteSink
Returned by write_stream() · write_handle_stream()
Streaming writer for file data to the sandbox. Obtained viawrite_stream() or write_handle_stream().
FsHandle
Returned by open_file() · open_dir()
Type alias for an agentd-side filesystem handle. Handles are valid only for the live relay client that opened them; close directly opened handles withclose_handle().