Skip to main content
See Your first sandbox for complete sync/async programs and connection rules. All three factory functions accept the configuration parameters of session_maker. Connect the SDK abstractions through a simple, extensible sandbox interface. ConTree’s stateless execution model differs from a classic stateful sandbox: filesystem state passes between executions through images and snapshots. This module assembles clients, sessions, stores, and policies to provide a familiar sandbox workflow without requiring users to connect each component. The default lazy session reuses a VM between commands. Snapshots preserve files, but do not preserve running processes or memory. Advanced users can select or extend session classes, supply components, and configure policies while keeping control over execution, state, and resource ownership.

class SandboxConfig

Attributes

str | None
str | None
str | None
str | None
Literal['iam', 'jwt'] | None
Profile | str | None
str | Path | None
type[SyncExecutor | AsyncExecutor] | None
str | None
str | None
SyncStore | AsyncStore | None
float
str | None
dict[str, str] | None
AbstractCommitPolicy | None
SyncFileTransfer | AsyncFileTransfer | None
dict[str, Any]
ContreeSyncClient | ContreeAsyncClient | None
type[ContreeSyncClient | ContreeAsyncClient] | None
dict[str, Any]

Methods

connection()

ConnectionConfig

resolve_profile()

Profile

validate()

required
None

session_arguments()

required
required
tuple[dict[str, Any], dict[str, Any]]

class SyncSandboxSessionContext

Construct a synchronous session and unwind its owned resources.

Methods

__enter__()

TypeVar(SyncSessionT, bound= SyncExecutor)
TypeVar(SyncSessionT, bound= SyncExecutor)

class AsyncSandboxSessionContext

Construct a native async session and join cleanup despite cancellation.

Methods

__aenter__()

TypeVar(AsyncSessionT, bound= AsyncExecutor)
TypeVar(AsyncSessionT, bound= AsyncExecutor)

class SandboxSessionContext

Compose sync and async contexts with one shared, single-use boundary. Construction performs no I/O. Entry chooses the context mode explicitly. Re-entry, nesting, and switching modes on the same object are rejected.

Methods

__enter__()

TypeVar(SyncSessionT, bound= SyncExecutor)
TypeVar(SyncSessionT, bound= SyncExecutor)

__aenter__()

TypeVar(AsyncSessionT, bound= AsyncExecutor)
TypeVar(AsyncSessionT, bound= AsyncExecutor)

create_sandbox_session()

Create a single-use context supporting both with and async with.
default:"None"
SandboxSessionContext[Any, Any]
SandboxSessionContext[Any, Any]A composed context. See session_maker for all configuration parameters.

create_sync_sandbox_session()

Create a sync-only context; its default session is LazySession.
default:"None"
SyncSandboxSessionContext[Any]
SyncSandboxSessionContext[Any]A synchronous context with the configuration accepted by session_maker.

create_async_sandbox_session()

Create an async-only context; its default session is AsyncLazySession.
default:"None"
AsyncSandboxSessionContext[Any]
AsyncSandboxSessionContext[Any]An asynchronous context with the configuration accepted by session_maker.

session_maker()

Prepare a sync/async sandbox context without opening connections or a VM. Without session_type, entry selects LazySession or AsyncLazySession. Explicit classes must implement SyncExecutor or AsyncExecutor and match the context mode. Lazy subclasses receive a base session; other classes receive a client and the standard ContreeSession constructor keywords. session_kwargs adds arguments to the selected class, never to the underlying lazy base session. Factory-managed arguments take priority over duplicates in session_kwargs. Connection arguments, an explicit profile/config_path, and a borrowed client are separate sources. Without an explicit source, use the client’s environment profile, then its default INI resolution. client_kwargs is forwarded unchanged to the selected client’s from_profile constructor. The default lazy policy snapshots after 10 idle seconds. Normal exit saves pending work; exceptional exit discards unsaved work. Snapshots retain files, not running processes. ContreeSession and ContreeAsyncSession save each command by default in a separate VM. Pass disposable=True to leave their history unchanged.
required
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"60"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
default:"None"
TypeVar(ContextT)
A single-use context owning its created client, memory store, and session. Supplied clients, stores, and file transfers remain caller-owned.

profile_from_args()

Build an explicit client profile without reading or writing configuration. The default configuration uses the client’s endpoint when URL is omitted.
required
default:"None"
default:"None"
default:"'iam'"
Profile
A regular contree-client Profile.
ValueError – Credentials, URL, or authentication type are invalid.