Introducing a new way to review your PRs.

Read the announcement

hatchet-dev / hatchet

🪓 An orchestration engine for background tasks, AI agents, and durable workflows

View on GitHub

31 documents · Updated Nov 23, 2026

docs / sandbox-execution-and-providers

Sandbox execution and providers

Sandbox execution gives Hatchet users a durable workspace for shell commands and files. Hatchet carries each sandbox action through a workflow task while a tenant-connected provider runs the isolated environment and stores its workspace state.

Sandbox execution

The sandbox is a provider-backed workspace that applications can create, use again later, and remove. The TypeScript SDK exposes this capability through hatchet.sandbox; application code talks to Hatchet rather than directly to a vendor. See Sandbox SDK and provider management for the SDK and console surfaces.

Each action is a turn tied to a sandbox. Commands return output and an exit code, so a failed command is a result that the workflow can handle rather than a transport error. The SDK checks request options and provider results at this boundary so invalid input and bad backend data do not move into later workflow work.

The sandbox lifecycle separates stopping a live environment from deleting its stored workspace state:

ActionResult
CreateStarts a new sandbox, or starts one from a snapshot or template.
ConnectReopens a sandbox by ID and restores it when it is not live.
ExecuteRuns a shell command and creates a workspace snapshot.
KillStops the live environment while keeping snapshots and files.
DeleteRemoves the sandbox and its stored snapshots and files.
ListFinds sandboxes by ID or metadata.

File operations use the same workspace boundary. Small content travels with the turn. Larger files use provider storage through signed HTTPS URLs, while the SDK keeps the file API the same for callers.

References: sdks/…/README.md• L10-14 sdks/…/README.md• L80-127 sdks/…/sandbox.ts• L245-329

Provider model

A provider is a sandbox vendor connected to a Hatchet tenant. It supplies the isolated environment while Hatchet keeps the common sandbox and snapshot model, which lets applications use different vendors without changing their workflow code. Supported provider kinds are Daytona, E2B, Archil, and Freestyle.

Provider selection is tenant-scoped. An application can name the provider when a tenant has more than one; a sandbox created from a snapshot must use the provider that owns that snapshot. Provider settings also supply a default template, an idle limit, optional vendor settings, and metadata for sandboxes created through that provider.

Machine size requests remain provider-aware. A provider can support, reject, or ignore a requested CPU, memory, or disk value. The shared sandbox API keeps this difference visible as a provider result instead of hiding vendor limits from the workflow.

References: sdks/…/README.md• L61-74 sdks/…/README.md• L87-99 sdks/…/sandbox.ts• L75-101 frontend/…/kinds.ts• L37-104

Snapshot state

Snapshots preserve workspace state between turns and let a new sandbox start from an earlier point. Creating more than one sandbox from the same snapshot creates independent workspace branches, while the provider relationship remains tied to the snapshot's owner.

Hatchet records the latest snapshot and the turn that produced it. This gives durable workflow execution a state trail without requiring the workflow to know how the provider restores or stores the workspace.

The state flow moves from a request to provider execution and then back through a snapshot:

flowchart LR
    A[Sandbox request] --> B[Provider-backed workspace]
    B --> C[Sandbox turn]
    C --> D[Workspace snapshot]
    D --> B
    D --> E[New sandbox branch]

References: sdks/…/README.md• L12-14 sdks/…/README.md• L93-97 sdks/…/sandbox.ts• L79-89 sdks/…/sandbox.ts• L315-329

Runtime access

Sandbox turns run through a Hatchet sandbox task, which is the runtime boundary between workflow code and the provider. The SDK finds the task registered for the tenant, sends the turn, and returns the provider-backed result. A durable workflow can therefore resume sandbox work after a crash without calling the vendor directly.

The SDK also exposes the turn contract for runtime services that start the task themselves. This shared contract covers requests, results, command output, sandbox information, resources, and metadata. Run metadata carries sandbox identity, provider, image, and snapshot context so operators can find related work in Hatchet.

The SDK supports both normal workflow runs and a fresh administrative run. It reports phase timings and snapshot identifiers so runtime services can observe the turn without depending on vendor-specific APIs. The SDK checks the current hatchet-sandbox task first and retains support for the older brickie-sandbox name during migration.

References: sdks/…/sandbox.ts• L15-51 sdks/…/sandbox.ts• L206-242 sdks/…/sandbox.ts• L331-371 sdks/…/CHANGELOG.md• L15-23 sdks/…/CHANGELOG.md• L41-48

Provider management

The console gives tenant operators one place to connect and manage vendor accounts. Access is gated by the tenant sandbox entitlement; users without it cannot open the provider pages.

Operators can connect a vendor with its API key, set a default template and idle limit, add vendor options, add default metadata, and choose whether the provider is enabled. The API key is stored by the service and is not shown again in the form. Provider changes are checked before submission and the list and detail views refresh to show the current state.

Provider health is separate from enabled state. A provider can be enabled but unhealthy when its vendor rejects the key, pending when it has not been checked, or healthy when the check succeeds. Operators can disable a provider without deleting its existing sandboxes; disabled providers serve no new turns until enabled again.

Deletion is stronger than disablement. It removes the provider's sandboxes, snapshots, and files from the Hatchet-managed provider state, while resources in the vendor account remain unaffected. The console requires explicit acknowledgement because runs that depended on those sandboxes cannot be replayed.

The management flow connects a tenant entitlement to provider configuration, health, and lifecycle actions:

flowchart TD
    A[Tenant entitlement] --> B[Provider management]
    B --> C[Connect or edit vendor]
    B --> D[Enable or disable provider]
    B --> E[Delete provider]
    C --> F[Health check]
    F --> G[Healthy or unhealthy state]
    D --> H[Provider accepts or rejects turns]
    E --> I[Hatchet sandbox state removed]

References: frontend/…/gate.tsx• L8-35 frontend/…/create-provider-dialog.tsx• L94-211 frontend/…/form-fields.tsx• L181-297 frontend/…/provider-status-badge.tsx• L10-47 frontend/…/disable-provider-dialog.tsx• L7-17 frontend/…/delete-provider-dialog.tsx• L20-33

Provider events

Provider events give operators a short history of credential checks and sandbox state changes. The detail view turns health, creation, turn, snapshot, and destruction events into a readable log and keeps the affected sandbox ID and event details when available.

These events connect a vendor failure to the tenant and sandbox that experienced it. They support diagnosis without changing the common SDK behavior across providers.

References: frontend/…/index.tsx• L65-75 frontend/…/index.tsx• L251-264 frontend/…/events-log.tsx• L11-49

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep provider selection aligned with snapshot ownership and provider-scoped sandbox state.
  • Keep the turn contract aligned between SDK actions, the registered sandbox task, shared wire types, run metadata, and snapshot results.
  • Keep provider kinds aligned across the SDK, console forms, API types, and vendor-specific configuration fields.
  • Keep enabled state, health state, and event labels aligned so operators can distinguish a disabled provider from a rejected credential.
  • Keep idle limits and resource units aligned between console values, wire values, provider limits, and provider errors.
  • Keep delete and disable behavior aligned across the SDK, provider service, and confirmation text. Disable must preserve existing sandboxes; delete must remove their stored state.
  • Keep large-file staging and signed-URL renewal aligned with durable task replay.

Important failure modes

TriggerConsequenceGuard
A tenant selects an unknown or disabled providerA sandbox turn cannot reach a usable backendValidate provider selection and enabled state before starting the turn
A snapshot is used with a different providerThe workspace cannot be restored from its stored stateBind snapshot use to its owning provider
A provider rejects its API keyNew sandbox work fails even though the provider record existsSurface health and the last error, then correct or replace the credential
A provider is disabledCreate, connect, command, and file turns fail while existing sandboxes remainRe-enable the provider before serving turns
A provider is deletedIts Hatchet-managed sandboxes, snapshots, and files are removed and dependent runs cannot replayRequire explicit deletion confirmation and use disable when state must remain
A resource request uses an unsupported or invalid sizeCreation fails or the provider uses a different supported sizeValidate units and surface provider capability errors
A provider result does not match the turn contractThe caller receives no trustworthy workspace resultValidate provider responses before returning them
A large-file URL expires during durable replayFile read or write fails even though the task can resumeRenew the signed URL through a fresh provider request

Key files

FileWhy to read it
sdks/…/README.mdGives the product model, provider relationship, lifecycle, file behavior, and user-facing limits.
sdks/…/sandbox.tsShows how the SDK turns sandbox actions into Hatchet workflow runs and preserves sandbox state.
sdks/…/CHANGELOG.mdRecords the current provider selection, resource, metadata, validation, and task migration contracts.
frontend/…/index.tsxShows the tenant provider list and the operator entry point for connecting a vendor.
frontend/…/index.tsxShows provider health, settings, events, and lifecycle actions in one operator view.
frontend/…/use-sandbox-providers.tsxShows the provider management boundary and the validation that shapes provider requests.
frontend/…/kinds.tsShows the supported vendors and the provider-specific settings exposed to operators.
frontend/…/delete-provider-dialog.tsxShows the data-loss boundary between disabling a provider and deleting its Hatchet-managed state.