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

Keeps a session's sandbox leased while the session needs it.

A session whose sandbox implements `c:Condukt.Sandbox.activity/2` starts
one lease process, linked to it. The session tells the lease when a turn
starts and ends; the lease calls the sandbox, so a slow call, such as one
that resumes a paused machine, never holds up the session:

  * `:active` once when a turn starts, and again every `:lease_interval`
    milliseconds (default `60_000`) while the turn runs or is parked;
  * `:idle` once the session has had no turn for `:idle_after`
    milliseconds (default `1_000`), so a queued turn that starts right
    after another does not give the sandbox up in between.

A session given a sandbox that is already leased, as a sub-agent is its
parent's, holds the same lease instead of starting another: the sandbox is
active while any of its sessions has a turn, and idle once none has. A
holder that exits counts as idle.

The lease does not call `:idle` when the session that started it exits. A
session that crashed or was drained for another node (see
`Condukt.Sessions.stop/2`) leaves its sandbox to whoever takes over, and
the sandbox's own expiry, such as a pod heartbeat or a residency's grace,
covers a session that never comes back.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

---

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