sbx.files reads and writes files inside the VM. Paths are paths in the sandbox, such as /workspace/app/package.json. The sandbox must be running.
Methods
How it works
The API has no file routes. The SDK runs ordinary commands in the sandbox’s shell:
What follows from that:
readandwritestream over the WebSocket, so there is no size cap and binary data round-trips byte for byte.list,exists,makeDirandremoveuse the buffered route, so each is limited to 55 s and 1 MiB of output. A directory with a very long listing comes back cut short.- Each call is one command.
writedoes not write atomically: a reader in the sandbox can see a partly written file.
Errors
When the command fails, the method throws aCommandError. It is a ZodeError with code command_failed, plus:
exitCode: the command’s exit codestderr: what the command printed, such ascat: /workspace/missing.txt: No such file or directory
exists never throws CommandError: any non-zero exit from test -e returns false. Errors from the API itself, such as invalid_state when the sandbox is stopped, come through as plain ZodeError. See Errors.