Skip to content

Reference for reading and writing the files of a sandbox or a volume.

A Sandbox and a Volume share these calls, each on its own files, by a path relative to its root such as dir/file.txt; the empty path is the root, and the server refuses one that leads outside. In Rust, they come from the Files trait, so use virtx::Files;. See Reading and writing files.

Member Does
stat_file What is at path: whether it is a directory, its size, its modification time, and its etag.
exists Whether anything, a file, or a directory is at path.
read_dir The entries of a directory, each with its name and metadata.
read_file A file’s bytes: from offset, length bytes or all that is left.
read_text A whole UTF-8 file as text.
write_file Writes a whole file, created if it does not exist; its parent directory must exist.
create_dir Creates a directory whose parent exists; create_dir_all creates its parents too, as mkdir -p, and is refused with 405 when a file is there.
remove_file Removes a file, or a directory with everything in it.
rename_file Moves a file or directory; refused onto something that exists unless overwrite.
copy_file Copies a file or directory with everything in it, replacing as rename_file does.

stat_file

What is at path: whether it is a directory, its size, its modification time, and its etag.

async def stat_file(path: str) -> Metadata

exists

Whether anything, a file, or a directory is at path.

async def exists(path: str) -> bool
async def is_file(path: str) -> bool
async def is_dir(path: str) -> bool

read_dir

The entries of a directory, each with its name and metadata.

async def read_dir(path: str) -> list[DirEntry]

read_file

A file’s bytes: from offset, length bytes or all that is left.

async def read_file(path: str, offset: int = 0, length: int | None = None) -> bytes

read_text

A whole UTF-8 file as text.

async def read_text(path: str) -> str

write_file

Writes a whole file, created if it does not exist; its parent directory must exist. With if_match, the etag a stat gave, only while the file still has it, and refused with 412 otherwise.

async def write_file(path: str, content: bytes | str, if_match: str | None = None) -> None

create_dir

Creates a directory whose parent exists; create_dir_all creates its parents too, as mkdir -p, and is refused with 405 when a file is there.

async def create_dir(path: str) -> None
async def create_dir_all(path: str) -> None

remove_file

Removes a file, or a directory with everything in it. With missing_ok, nothing being there is fine, as rm -f.

async def remove_file(path: str, missing_ok: bool = False) -> None

rename_file

Moves a file or directory; refused onto something that exists unless overwrite.

async def rename_file(from_path: str, to_path: str, overwrite: bool = False) -> None

copy_file

Copies a file or directory with everything in it, replacing as rename_file does.

async def copy_file(from_path: str, to_path: str, overwrite: bool = False) -> None

Errors

A call that fails raises a VirtxError in Python, throws one in Node.js, and returns one in Rust. Branch on its status and code, not its message. These are the errors the calls on this page return most often.

Error From Cause
source client Any call The path’s .. leads above the root. The client resolves . and .. itself, so a/../b is sent as b, and refuses a path that climbs above the root without sending it.
403 Writes, remove_file, rename_file A write to a volume mounted read-only, or a move or remove of the root itself.
404 Any call but exists, is_file and is_dir Nothing is at that path, or the sandbox or volume doesn’t exist. For remove_file, pass missing_ok to treat it as done. exists, is_file and is_dir answer false instead.
405 create_dir_all A file is at that path.
409 write_file, create_dir The parent directory doesn’t exist. Create it with create_dir_all.
409, ended Any call on a sandbox The sandbox’s VM has stopped for good. Create another sandbox.
412 copy_file, rename_file The destination exists. Pass overwrite.
412 write_file with if_match The file changed since you read its etag. Read it again with stat_file, then retry.
An error that mentions UTF-8 read_text The file isn’t UTF-8 text. Read its bytes with read_file.

Any call can also fail with 401, unauthorized or 403, forbidden (see Client), or with source transport when the connection drops. The client retries 503, capacity and a 429, quota for the request rate by itself for up to 30 seconds: see Retries.