Quick Example
Mount a host directory read-write at/workspace in the sandbox, write a file from inside the sandbox, then return to the host to verify that it appears.
Parameters and Returns
Mounts are configured through thevolumes parameter on BoxOptions / SimpleBox. Each element describes one mount.
Python: a volumes element accepts three forms
Field types:
Key point (the most common mistake): the third element is a booleanRead-only mount example:True/False, not the string"ro"/"rw". The string syntax is only for the CLI formboxlite -v host:guest:roand is not interchangeable with the SDK.
Node: a volumes element is an object
Return value
volumes is a creation-time configuration option and has no return value of its own. Whether a mount took effect is observed by inspecting files with exec inside the sandbox. exec returns an ExecResult:
Moving files without a mount
A mount is the right tool when the host and the sandbox need to share a directory for the whole session. For a one-off transfer — ship in a script, pull back a result — copy the file directly. This also works when the target is a read-only mount or a tmpfs path, where writing from inside the box would not reach the host.
Both methods are
async and return None; failures raise.
Troubleshooting
Passing the string "ro"/"rw" for read_only -> TypeError
True for read-only, False for read-write (or omit the third element to get read-write):
ro/rw apply only to the CLI form -v host:guest:ro and should not be used with the SDK.
A tuple whose length is not 2 or 3 -> RuntimeError
(host, guest) or (host, guest, read_only).
A dict missing the host / guest key -> RuntimeError
host or host_path) and a guest key (guest or guest_path).
Files written to /tmp or /dev/shm are not found on the host
Inside the sandbox, /tmp and /dev/shm are tmpfs (in-memory filesystems) provided automatically by the runtime. They are not part of any mounted host directory, and they are not persisted with the sandbox: they disappear once the sandbox is destroyed.
Fix:
- To write data back to the host: write to a mounted directory (such as
/workspacein the example), not to/tmp. - The destination of
copy_in/copyInshould also avoid tmpfs paths (such as/tmp,/dev/shm); otherwise the copied files will not land in the expected persistent layer of the container. Use a non-tmpfs path such as/root/instead. - The SDK does not expose parameters to customize the tmpfs size or mount point; tmpfs is managed entirely by the runtime internally.
Writing a file fails on a read-only mount
On a read-only mount (read_only=True), any write to that path from inside the sandbox fails (typically Read-only file system). A non-zero exit code from exec does not raise; check exit_code yourself:
read_only=False, or omit the third element).
The host directory does not exist / the path is relative
When the mount point shows no content, or startup reports a path-related error, first confirm that the host path exists and is absolute. Relative paths are not resolved to the directory you expect. In Python, normalize withos.path.abspath(...) before passing the path.
The sandbox fails to start (no virtualization)
In an environment without hardware virtualization (Linux without KVM, WSL2 without KVM enabled, and so on), startup fails and raisesRuntimeError (the process itself does not crash and the error is catchable). This is an environment constraint: you need Linux with KVM, or run on macOS (which uses Hypervisor.framework automatically).
