Skip to main content
This page collects the execution-related shapes and state machine that sit between the host and an environment module.

ExecutionInput

What the host hands to EnvironmentModule.execute:
  • eid is the execution id. It is the same number as the process pid. Treat it as opaque; just feed it back to every binding.
  • code is exactly what the client submitted via POST /processes.
  • envConfig is a generic bag of environment-level configuration set by the host. The host guarantees at minimum a timeoutMs key, resolved against DEFAULT_EXECUTION_TIMEOUT_MS (30000) before dispatch. The environment should treat this as authoritative and pluck the values it recognises.

Host-side States

The host’s ProcessService runs the public-facing state machine. From the API’s perspective, a process is always in one of four states:
  • idle: Not executing. Either pre-run, or post-run with an exit state.
  • queued: Accepted, waiting for the environment.
  • running: Environment is executing the code.
  • terminating: A kill is in flight.

Environment-reported States

EnvironmentBindings.setState(eid, data) accepts only the environment states:
The host maps these to its own state machine. idle and terminating are host-only; the environment never reports them.

Exit States

The environment’s execute returns one of these. The host stores it as process.exitState: The host also accepts null as a transient pre-execution value, but environment code never returns null.

Timeout Contract

The host hands the environment a timeoutMs within envConfig and expects the environment to enforce it. The host does not run a wall clock of its own; if the environment lies about exit state, the process record lies too.
  • The bundled typescript-ivm enforces the timeout by racing the isolate against a setTimeout, then disposing the isolate.
  • Custom environments are free to use any mechanism, process group signals, worker thread interrupts, whatever fits the runtime.

Cancellation Contract

EnvironmentModule.kill(eid) is the only way the host asks for cancellation. The environment should:
  1. Stop whatever is executing for eid promptly.
  2. Resolve the outstanding execute(eid) promise with "canceled".
  3. Be safe to call with an eid it does not know about.
There is no “soft kill” channel. If you need cooperative shutdown for long-running tools, model it inside the runtime (e.g. an AbortController exposed to user code).

What the host owns

What the environment owns

Last modified on July 4, 2026