# `Condukt.Sandbox.Setup`
[🔗](https://github.com/tuist/tuist/blob/condukt@3.0.0/condukt/lib/condukt/sandbox/setup.ex#L1)

Prepares a sandbox before a session's first turn, and again when the
session comes back on a sandbox that was paused.

`prepare/3` runs a repository's setup script as a sandbox process, streams
its output to `:on_output`, and, when the script succeeds and the sandbox
implements `c:Condukt.Sandbox.snapshot/2`, saves a snapshot. A later
sandbox started with that snapshot (its `init/1` takes `:snapshot`) skips
the setup. `resume/3` runs a resume script, such as one that starts what a
pause stopped, the same way, without a snapshot.

    {:ok, %{snapshot: snapshot_id}} =
      Condukt.Sandbox.Setup.prepare(sandbox, File.read!(".agents/setup"),
        on_output: &IO.write/1,
        snapshot: [key: "repo@" <> sha]
      )

Which snapshot to boot from, and when to refresh it, is the host's policy:
Condukt only runs the script and asks the sandbox to save.

# `prepare`

Runs `script` and saves a snapshot when it succeeds. Options:

  * `:on_output` — a function given each chunk of output
  * `:snapshot` — options for `c:Condukt.Sandbox.snapshot/2`, or `false`
    to skip saving
  * `:timeout`, `:cwd`, `:env` — as `c:Condukt.Sandbox.start_process/4`

Returns `{:ok, %{snapshot: id_or_nil}}`, or `{:error, {:setup_failed,
status, tail}}` with the end of the output.

# `resume`

Runs a resume script. Takes `prepare/3`'s options but `:snapshot`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
