create_sandbox_session connects the SDK components into a familiar sandbox
interface. ConTree executes from filesystem images; a long-lived, mutable VM is
not its persistence model. The default LazySession provides continuity between
commands, then saves files at a snapshot boundary.
Use the factory for normal application code. Build the components directly when
you need to control their construction, share them, or replace their behavior.
These examples show the components behind the default sandbox and their cleanup
order. Configure a connection as described in Connection sources and use
an available image with sleep, a POSIX shell, and cat.
What the factory supplies
The factory reuses uploads through the same Store, with
cache_ttl=60 by default.
See Reuse uploads and retain their sources for lifetime and connection-scope details.
Build the default components explicitly
Both programs write a file, read it in the same VM, and printHello from ConTree!. Normal exit saves pending filesystem changes. An exception
inside the lazy context discards changes since its last completed snapshot.
- Sync
- Async
ensure_ready() resolves the initial image and history; it does not start a VM.
The first lazy command starts the VM. The lazy context exits before the store and
client contexts, so saving can still use both components.
These programs show ordinary component assembly. The factory also handles partial
entry failures, preserves a body exception if cleanup fails, and joins async
cleanup under repeated cancellation. Reuse its context implementation when those
guarantees are needed in a custom factory; see Sandbox factories.
Change one component without rebuilding everything
The factory accepts the same extension points. This selects a custom base session that adds a default command timeout. Each command uses an independent operation.- Sync
- Async
ContreeSession or ContreeAsyncSession saves each command by default
in a separate VM. Use disposable=True to leave the session image unchanged.
Selecting a lazy subclass retains a shared VM until a snapshot. Snapshots are
lightweight and can run after every command, but they stop the VM. An unchanged
filesystem can produce the same image UUID. session_kwargs
configures the selected class; store, file_transfer, and commit_policy
configure its underlying base session. To supply a custom base session inside a
lazy wrapper, assemble them directly as above.
Continue with Customize the SDK for public hooks and component contracts,
and Sessions and operations for snapshot policies. Snapshots
preserve files, not processes, memory, or sockets.