Skip to content

Host paths

A sandbox sees nothing of the host's files unless it is given them. There are three ways to give it a directory, and they differ in one thing that matters most: whether what the sandbox does reaches the host.

Shared, cloned or copied

Marker of a task Client and spec The sandbox gets Back on the host
WorkspaceDir() client.create(workspace=dir), with_workspace(dir) The directory itself, mounted read-write at its own path, as its working directory Everything, at once: a file the sandbox writes or deletes is written or deleted on the host
WorkspaceDir(clone=True) client.create(workspace=dir, clone=True), with_cloned_workspace(dir) A private Git clone of the repository, at the same path, with its history; the repository itself mounted read-only at /run/sandbox/source Nothing: commits stay in the clone, removed with the sandbox
Mounted(target, read_only) Workspace(dir, read_only, target) in workspaces or with_mount A further directory or file, at target or its own path, read-write unless read_only=True Everything written, unless read-only
Uploaded(target) upload_dir(), write_file() A copy of the contents, made once the sandbox runs Nothing
  • A workspace has no read-only form: use a clone, an upload or a read-only mount when the sandbox must not change the files.
  • A further mount needs a workspace: a task with a Mounted input and no WorkspaceDir raises InvalidSpecError before anything is created.
  • A task takes at most one WorkspaceDir.
  • A task expands (~) and resolves the paths of its inputs on the host, before the launch.

What comes back

From a clone or an upload, nothing comes back on its own: the task reads what it keeps before the run ends. It can return a file it reads (read_text()), a directory it downloads (download_dir()), or the commits of the clone as a patch, made with git format-patch in the sandbox: see Working with repositories. With keep=True, the sandbox stays, its clone in it.

Clones

A clone holds the commits of the branch checked out on the host, with its history, and nothing else: no change left uncommitted, staged or not, no untracked or ignored file, and a submodule is not checked out. Git LFS files were not measured. Commit what the sandbox must see, or upload it. fastsandbox adds no Git remote to the host repository.

What a read-write directory exposes

A coding agent runs with its approvals turned off. Given a read-write directory, it can change any file in it, including files that run later on the host without a review: Git hooks, which git diff does not show, CI configuration, a Makefile, the scripts of a package.json. Review what comes back before you run it, and prefer a clone, whose work comes back as a patch you read.

Next