Skip to content

RuntimeFactory

Category: Runtime

Source: runtime_factory.dart

Enums

RuntimeDiffUnavailableReason

ValueDescription
executorDead

Classes

abstract RuntimeSession

Per-session runtime — owns the [CommandExecutor] and [Workspace] that tools route through, plus the lifecycle hook glue calls on session shutdown.

Built-in implementations:

  • host / docker — returned by [RuntimeFactory.create] directly; exposed as anonymous instances via [_BuiltinRuntimeSession].
  • Cloud adapters (daytona, sprites, modal) implement this interface on their *Runtime class so callers can read sandbox metadata uniformly.

[sandboxId] and [bootstrapSha] are best-effort diagnostics for cloud runtimes; built-in runtimes return empty / null.

Properties

PropertyTypeDescription
idString getAdapter id: 'host', 'docker', 'daytona', 'sprites', 'modal', … Stable across sessions, used for capability lookup and /runtime display.
sandboxIdString getPer-runtime sandbox identifier (Daytona sandbox id, sprite name, Modal sandbox object id). Empty string for host/docker runtimes that have no per-session sandbox.
bootstrapShaString? getCommit SHA the workspace was bootstrapped from inside the sandbox. null for host/docker (no bootstrap) and for cloud sandboxes that were resumed from an existing /workspace/.git.
resumedbool getTrue when the runtime resumed an existing sandbox instead of creating a fresh one. Always false for host/docker.
executorCommandExecutor getThe executor that [BashTool] and friends route through.
workspaceWorkspace getThe workspace that [ReadFileTool] / [WriteFileTool] / etc. route through.
patchString
metaRuntimeDiffMeta
metaRuntimeDiffMeta
reasonRuntimeDiffUnavailableReason
hintString?
idString getAdapter id: 'host', 'docker', 'daytona', 'sprites', 'modal', … Stable across sessions, used for capability lookup and /runtime display.
sandboxIdString getPer-runtime sandbox identifier (Daytona sandbox id, sprite name, Modal sandbox object id). Empty string for host/docker runtimes that have no per-session sandbox.
bootstrapShaString? getCommit SHA the workspace was bootstrapped from inside the sandbox. null for host/docker (no bootstrap) and for cloud sandboxes that were resumed from an existing /workspace/.git.
resumedbool getTrue when the runtime resumed an existing sandbox instead of creating a fresh one. Always false for host/docker.
executorCommandExecutor getThe executor that [BashTool] and friends route through.
workspaceWorkspace getThe workspace that [ReadFileTool] / [WriteFileTool] / etc. route through.

Methods

Future<void> close()

Releases runtime resources on session shutdown. Host/docker runtimes return immediately; cloud runtimes stop the sandbox (or leave it to auto-sleep when delete_on_close: false).

Future<RuntimeDiffOutcome> diffSinceBootstrap()

Returns the outcome of attempting to diff the runtime workspace against [bootstrapSha]. The default implementation reports [RuntimeDiffOutcomeUnavailable] (host/docker, no diff capture). Cloud runtimes override this to return [RuntimeDiffOutcomeSuccess], [RuntimeDiffOutcomeEmpty], or [RuntimeDiffOutcomeUnavailable] with a typed reason and a hint.

Returning unavailable is explicitly not the same as "no changes". Surfaces must turn unavailable into a visible warning so the user knows the session didn't silently lose their work.

const RuntimeDiffOutcome()
const RuntimeDiffOutcomeSuccess({required this.patch, required this.meta})
const RuntimeDiffOutcomeEmpty({required this.meta})
const RuntimeDiffOutcomeUnavailable({required this.reason, this.hint})

sealed RuntimeDiffOutcome

Surface-facing mirror of DiffOutcome from glue_runtimes/common/diff.dart. Lives here so glue_strategies consumers can pattern-match without importing the runtime adapter package.

Constructor

dart
const RuntimeDiffOutcome()

RuntimeDiffOutcomeSuccess

Constructor

dart
const RuntimeDiffOutcomeSuccess({required this.patch, required this.meta})

Properties

PropertyTypeDescription
patchString
metaRuntimeDiffMeta

RuntimeDiffOutcomeEmpty

Constructor

dart
const RuntimeDiffOutcomeEmpty({required this.meta})

Properties

PropertyTypeDescription
metaRuntimeDiffMeta

RuntimeDiffOutcomeUnavailable

Constructor

dart
const RuntimeDiffOutcomeUnavailable({required this.reason, this.hint})

Properties

PropertyTypeDescription
reasonRuntimeDiffUnavailableReason
hintString?

RuntimeDiffMeta

Constructor

dart
const RuntimeDiffMeta({
    required this.runtimeId,
    required this.sandboxId,
    required this.bootstrapSha,
    required this.remoteUrl,
    required this.runtimeCwd,
    required this.format,
    required this.capturedAt,
    required this.sizeBytes,
  })

Properties

PropertyTypeDescription
runtimeIdString
sandboxIdString?
bootstrapShaString?
remoteUrlString?
runtimeCwdString
formatString
capturedAtDateTime
sizeBytesint

RuntimeFactory

Builds a [RuntimeSession] for runtime: <name> from config.

Two runtimes are built in: host and docker. Cloud adapters (daytona, sprites, modal) register themselves via [register] from a surface (cli/bin/glue.dart) at startup — this keeps glue_strategies free of any dependency on cloud-specific packages.

Methods

static void register(String name, RuntimeAdapter adapter)

Registers a cloud adapter under [name]. The surface (cli) calls this once at startup before [create] is invoked.

static Iterable<String> registeredAdapters()

Returns the set of registered cloud-adapter names. Useful for glue doctor and the /runtime slash command.

`static Future<RuntimeSession> create({
required String runtime,
required ShellConfig shellConfig,
required DockerConfig dockerConfig,
required String cwd,
Map&lt;String, Object?&gt; runtimeOptions = const {},
List&lt;MountEntry&gt; sessionMounts = const [],
bool? dockerAvailable,
RuntimeEventSink? eventSink,

})`

Resolves the runtime named [runtime] and returns its session.

  • 'host' → [HostExecutor] + identity [LocalWorkspace].
  • 'docker' → [DockerExecutor] + identity [LocalWorkspace] (Docker bind-mounts the host cwd so the host filesystem stays authoritative).
  • any other value → a registered adapter, or [StateError] if none is registered.

[runtimeOptions] holds the YAML section for the named runtime (e.g. the daytona: block when runtime: daytona is selected). Cloud adapters parse this on startup; host/Docker ignore it.

RuntimeInfoSnapshot

Snapshot of the immutable runtime metadata that surfaces persist alongside the session (SessionMeta) so /resume, glue session …, and the cleanup sweep have a stable handle on what runtime the session used.

Constructor

dart
const RuntimeInfoSnapshot({
    required this.runtimeId,
    required this.sandboxId,
    this.bootstrapSha,
    this.remoteUrl,
  })
dart
factory RuntimeInfoSnapshot.from(RuntimeSession session)

Builds a snapshot from a live [RuntimeSession]. Cheap — just reads getters and shapes the data.

Properties

PropertyTypeDescription
runtimeIdString
sandboxIdString
bootstrapShaString?
remoteUrlString?

Released under the MIT License.