Every computer presents the same two writable places, whatever is underneath.
| Path | What it is |
|---|---|
/work | The working directory. The default cwd for every command |
/tmp | Scratch. Cleared with the machine |
That uniformity is the point of the abstraction: an agent writing to /work/out.csv
does not need to know whether it is in a container, on a remote box, or in a directory
on your laptop.
What is underneath
| Provider | /work | /tmp |
|---|---|---|
docker, podman | tmpfs, <diskMb or 2048>m, rw,exec,nosuid, mode 1777. A named volume when persist: true: husk-<id>, or husk-key-<key>-<digest> for a chat's or a bot's computer | tmpfs, 512m |
local | ~/.husk/workspaces/<id>/root. On WSL it is in the distro's home, which Windows reaches at \\wsl.localhost\<distro>\…, and is bind-mounted onto /work inside unshare -mr | ~/.husk/workspaces/<id>/tmp |
ssh | $HOME/.husk-work/<id>/work on the remote box | $HOME/.husk-work/<id>/tmp |
fly | The microVM's own filesystem | The microVM's own filesystem |
On the container providers the root filesystem is mounted read-only. Anything written
outside /work, /tmp and /run fails loudly rather than mutating an image layer that
is about to disappear.
On local with WSL, the bind mount is created per exec inside a user and mount
namespace, so two computers can both have a /work, each its own. It does not hide one
from the other: a shell command can still read another computer's files under
~/.husk/workspaces/. The one prerequisite is an empty /work directory to mount onto,
which cannot be created from inside the namespace — Husk creates it once, as root, and
says so.
If WSL is unavailable, the local provider cannot present a /work at all, so it
reports the real host path as the workdir instead. A fictional workdir is worse than an
ugly one.
On ssh, and on local on macOS or Linux, nothing mounts a /work either. There a
command's /work and /tmp paths are rewritten to the real directories before it runs,
so cat /work/a.txt reads the file write_file wrote. The rewrite reads the command as
written: a path inside a heredoc's body, or one a program builds while it runs, still
names a /work that is not there.
Persistence
By default nothing survives the machine. husk rm takes the filesystem with it and there
is no snapshot taken on your behalf.
computer:
persist: trueOn the container providers that swaps the /work tmpfs for a named Docker volume, so
the filesystem survives husk stop and husk start. A chat's computer is made with
persist: true.
The volume of an anonymous computer goes with husk rm. One a chat or a bot made, under
its key, does not: husk rm on it means "stop for now", and the next computer with that
key finds the same files, the browser's logins in /work included. husk rm --erase,
like the console's Delete, takes the volume too.
Getting files in and out
husk cp ./report.csv scratch:/work/report.csv
husk cp scratch:/work/out.json ./out.json
husk cp ./src scratch:/work/srcDirectories are copied recursively. On local and ssh, both directions go through
the path jail.
For an agent, the same job is done by the write_file, read_file and edit_file
tools, or by the equivalent MCP tools.
The path jail
On local and ssh, every filesystem-API call resolves its target and rejects anything
outside /work and /tmp. On Docker, Podman and Fly the container is the boundary, and
the API reaches all of it. There are two checks and they do different jobs:
- Lexical, in
toHostPath. Normalises the guest path, maps it onto the host directory, and refuses a result that is not inside. Correct for..traversal and for absolute paths pointing elsewhere on the machine. - Resolved, in
assertInJail. Callsrealpathand confirms the real target is still inside, so a symlink created inside the workspace that points out of it is caught before any operation that would follow it. It checks the nearest existing ancestor rather than the leaf, so it works for a path that is about to be created, and a link whose target does not exist yet is judged by that target. Onsshthe same check runs on the remote box, withreadlink -m.
error path escapes the workspace: /work/../../secrets
hint: paths must stay inside /work or /tmp
error path is outside the machine's writable area: /etc/passwd
hint: this computer exposes /work and /tmp; use a path under one of them
error path resolves outside the workspace through a symlink
hint: husk refuses to follow links that leave the machineOutput caps
Captured output is clamped so a runaway process cannot exhaust memory. The default is
256 KiB per stream; limits.maxOutputBytes in a husk.yaml changes it, and the control
plane caps a caller's request at 16 MiB.
Clamping keeps the head and the tail, splitting the budget 60/40 in favour of the head, and says how much it dropped:
<first 60% of the output>
... [1048576 bytes elided by husk] ...
<last 40% of the output>The middle of a runaway build log is never the interesting part; the command that started it and the error that ended it are.
Timeouts
exec defaults to 120 seconds. On local, a timeout kills the whole process group
rather than just the shell — a detached child on POSIX gets its own process group, and
on Windows taskkill /T /F walks the tree. In a container, on an ssh box, on a Fly
machine and in a WSL distro, killing the client leaves the command running, so every
command carries a tag in its environment, and a timeout or a cancel kills each process
with that tag, inside the computer. The result reports exitCode: 124 and
timedOut: true.
Snapshots
snapshot() and restore() are optional methods on Computer, implemented by the
container providers and absent from local, ssh and fly. Feature-detect:
if (computer.snapshot) {
const { id } = await computer.snapshot('before-migration');
}There is no husk snapshot command. The capability is reachable through the library, not
the CLI.