Skip to main content
The filesystem API lets you read, write, and manage files inside a sandbox without mounting volumes or SSH. It uses the same channel as command execution, so it doesn’t touch the sandbox’s network. Handy for pushing generated code into a sandbox, pulling back results, or inspecting logs without having to pre-mount a shared directory.

Write a file

sb.fs().write("/app/config.json", r#"{"debug": true}"#).await?;

Read a file

let content = sb.fs().read_to_string("/app/config.json").await?;

List a directory

let entries = sb.fs().list("/app").await?;
for entry in entries {
    println!("{}: {:?}", entry.path, entry.kind);
}

Stream large files

For files too large to fit in memory, use streaming. Data is transferred in chunks of approximately 3 MiB each.
let mut stream = sb.fs().read_stream("/app/data.bin").await?;
while let Some(chunk) = stream.next().await {
    process(chunk?);
}

Copy from host

Copy a file from the host machine into the sandbox in a single call.
sb.fs().copy_from_host("./local-file.txt", "/app/remote-file.txt").await?;
If you need to transfer many files at once, consider using a bind-mounted volume instead. Volumes give the guest direct filesystem access, whereas the filesystem API transfers each file individually. For bulk operations, volumes are significantly faster.