Skip to main content
A file written inside the sandbox appears on the host immediately, and the reverse. Use it to feed in a dataset or repository, to mount weights and configuration read-only, or to keep results after a box is destroyed. The host path must be absolute and already exist.

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.
Node version (same read-write mount):

Parameters and Returns

Mounts are configured through the volumes 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 boolean True/False, not the string "ro"/"rw". The string syntax is only for the CLI form boxlite -v host:guest:ro and is not interchangeable with the SDK.
Read-only mount example:

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

Error:
Fix: use a boolean for the third element. Use True for read-only, False for read-write (or omit the third element to get read-write):
The strings 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

Error:
Fix: each mount must be written exactly as (host, guest) or (host, guest, read_only).

A dict missing the host / guest key -> RuntimeError

Error:
Fix: the dict must contain both a host key (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 /workspace in the example), not to /tmp.
  • The destination of copy_in / copyIn should 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:
To allow writes, make the mount read-write (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 with os.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 raises RuntimeError (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).