Skip to main content

rewind

sleep(duration)

Waits for duration: a number of milliseconds, or a string such as "30s", "10d" or "1h30m" (units ms, s, m, h, d, w). The wait is durable: the run survives restarts and deploys, and costs nothing while it waits. Afterwards, Date.now() is at least the time before plus duration.

signal(name, opts?)

Waits for the next signal named name sent to this run, and returns its payload. A signal sent before the script waits is kept in the name’s mailbox, first in, first out, so none is lost. With a timeout, returns undefined if none arrived in time; without one, the wait lasts as long as the run. Names starting with rewind: are reserved. In a run of a workflow, name must be one of its declared signals, and the payload has the declared type.

webhook(name)

Returns a unique URL bound to this run and the signal name: every request posted to it becomes a signal name on this run, with the request’s body as payload. Give the URL to an external system, then wait with signal(name).

run

This run. A fork has its own id, so a script that reads run.id diverges from its parent there.

ToolError

Thrown by a tool call that failed. Catch it to handle the failure; uncaught, it fails the run.

CancelledError

Rejects every pending await of the script when the run is cancelled. Catch it to clean up: the script then has one chance to end by itself.

WorkflowError

Thrown by result() when a run of a workflow this run started failed, was cancelled or aborted, or returned an output its workflow’s schema refuses.

rewind:tools

Generated for the run’s toolset: one export per MCP server (by the name the toolset gives it) or group of host tools, and one per host tool without a group. Each tool is an async function taking one object of arguments.
Arguments are validated against the tool’s schema before the call is recorded: invalid arguments throw a TypeError at the call site. A failed call throws a ToolError.

rewind:workflows

Generated for the run’s toolset: one export per workflow it pins.
A run started without detached: true is attached: this run does not end before it, and cancels it if this run fails or is cancelled.

Globals

The sandbox has the ECMAScript built-ins (ES2025, Temporal, explicit resource management) and exactly these globals: The isolate runs with TZ=UTC and the en-US locale. See The sandbox for what is removed and why.