Concept

Data contracts

@enclave/shared is the single source of truth for the wire format — pure TypeScript types, no runtime. The control plane, SDK, MCP server, console, and demo all import them, so the pieces can't drift.

CreateSessionRequest#

The request to create and run a session. Only code is required.

FieldTypeDescription
codestringThe untrusted source-code blob the sandbox will execute.
language?"python" | "node"Runtime of the blob. Defaults to python.
limits?SessionLimitsPer-session CPU / memory / wall-clock / pids quotas. Control plane fills defaults.
egress?EgressPolicyEgress policy. Defaults to deny_all.
serviceBindings?string[]Ids of service bindings to grant — secrets injected at the egress proxy, never in the sandbox.
webhookUrl?stringURL to receive the result event on completion.
labels?Record<string,string>Free-form operator labels (shown in the console).

Session#

The public view of a session. No brokered secret is ever present — the type has no token field at all.

FieldTypeDescription
idstringSession id.
orgIdstringOwning org — the tenancy boundary. Every session belongs to exactly one org.
createdBystringUser id (JWT sub) or API-key id of the principal that created it.
phaseSessionPhasepending | running | succeeded | failed | killed | torn_down.
language"python" | "node"Runtime that ran the workload.
limitsRequired<SessionLimits>The effective quotas after defaults.
egressEgressPolicyThe effective egress policy.
killReason?KillReasonSet when phase === killed.
result?SessionResultPresent once terminal.
backendstring"simulator" | "kubernetes" | "docker".
labelsRecord<string,string>Free-form operator labels carried through from the request.
createdAt / startedAt / finishedAtstring (ISO)Lifecycle timestamps.
Invariant 1
The Session type has no token field, and publicView() is structuredClone(session) — so it structurally cannot leak a brokered secret. Tests assert no eyJ… JWT appears in any response.

SessionResult#

FieldTypeDescription
exitCodenumber | nullProcess exit code, or null if killed before exit.
stdoutstringCaptured standard output.
stderrstringCaptured standard error.
json?unknownParsed JSON the workload wrote via enclave.result().
durationMsnumberWall-clock duration in milliseconds.

EgressPolicy & SessionLimits#

FieldTypeDescription
egress.mode"deny_all" | "allowlist"deny_all is the secure default — empty NetworkPolicy egress, also blocking the metadata IP.
egress.allow?string[]When allowlist, the permitted CIDRs. Empty == deny_all.
limits.cpuMillis?numberCPU limit in millicores (default 500).
limits.memoryMiB?numberMemory limit in MiB (default 256).
limits.wallClockSeconds?numberJob activeDeadlineSeconds (default 30).
limits.pidsLimit?numberMax process count — fork-bomb guard (default 128).

AuditEvent#

Recorded immutably per session. The type is one of: session_created, sandbox_started, egress_allowed, egress_denied, quota_killed, workload_exited, result_collected, webhook_delivered, webhook_failed, session_torn_down.

FieldTypeDescription
tsstring (ISO)When the event occurred.
sessionIdstringThe session it belongs to.
typeAuditEventTypeThe event category (see above).
messagestringHuman-readable summary.
data?Record<string,unknown>Structured context (host, exitCode, reason). Never contains secrets.

StreamFrame#

The SSE frame type — a discriminated union on kind, emitted on GET /sessions/:id/stream.

shared/src/index.tsts
type StreamFrame =
  | { kind: "phase";  phase: SessionPhase; ts: string }
  | { kind: "stdout"; chunk: string; ts: string }
  | { kind: "stderr"; chunk: string; ts: string }
  | { kind: "audit";  event: AuditEvent }
  | { kind: "result"; result: SessionResult; ts: string }
  | { kind: "end";    phase: SessionPhase; ts: string };

Auth contract#

The identity types shared by console-api (which mints) and the control plane (which verifies). Helpers signUserJwt, verifyUserJwt, and parseApiKey live alongside them.

FieldTypeDescription
Role"owner" | "admin" | "developer" | "viewer"Membership role within an org.
Scope"sessions:read" | "sessions:write" | "audit:read"Capability strings carried by a principal.
Principal.userIdstringStable subject id — the JWT sub, or the API-key id.
Principal.orgIdstringThe org the request is scoped to.
Principal.roleRoleThe principal's role within orgId.
Principal.kind"user" | "apiKey"How the principal authenticated.
Principal.email?stringEmail, when known (user JWTs carry it).
Principal.scopesScope[]Resolved capabilities.