Workflow Globals

Global APIs available inside workflow functions.

Workflow functions run in a restricted environment that prevents access to non-deterministic or side-effecting APIs. This page lists all global APIs available inside "use workflow" functions.

For full Node.js runtime access, use step functions.

Deterministic APIs

These APIs are available but are seeded or fixed to ensure deterministic behavior across replays.

APIBehavior
Math.random()Seeded random number generator — same seed produces the same sequence every replay
Date / Date.now() / new Date()Returns a fixed timestamp that advances with the workflow's logical clock
crypto.getRandomValues()Seeded — produces deterministic output for a given workflow run
crypto.randomUUID()Seeded — produces deterministic UUIDs for a given workflow run
crypto.subtle.digest()Passes through to the real implementation (SHA-256, etc. are deterministic by nature)

You can safely use Math.random(), Date.now(), and crypto.randomUUID() in workflow functions. The framework ensures these return the same values across replays.

Web Platform APIs

These standard Web APIs are available in workflow functions:

Environment Variables

process.env is available as a read-only, frozen snapshot of the environment variables at the time the workflow was started. You cannot modify it.

export async function myWorkflow() {
  "use workflow";

  const apiKey = process.env.API_KEY; // works
  process.env.FOO = "bar"; // throws — process.env is frozen
}

Binary Data

Standard JavaScript typed arrays (Uint8Array, Int32Array, Float64Array, etc.) are available in workflow functions.

Base64 and hex encoding

The workflow environment provides Uint8Array base64 and hex methods for encoding and decoding binary data:

// Encode to base64
const bytes = new Uint8Array([72, 101, 108, 108, 111]);
bytes.toBase64(); // "SGVsbG8="
bytes.toBase64({ alphabet: "base64url" }); // URL-safe variant
bytes.toBase64({ omitPadding: true }); // "SGVsbG8"

// Decode from base64
Uint8Array.fromBase64("SGVsbG8="); // Uint8Array([72, 101, 108, 108, 111])

// Encode to hex
bytes.toHex(); // "48656c6c6f"

// Decode from hex
Uint8Array.fromHex("48656c6c6f"); // Uint8Array([72, 101, 108, 108, 111])

// Write into an existing array
const target = new Uint8Array(5);
target.setFromBase64("SGVsbG8="); // { read: 8, written: 5 }
target.setFromHex("48656c6c6f"); // { read: 10, written: 5 }

These methods are polyfilled in the workflow environment. When the JavaScript runtime ships native support, the polyfill is automatically bypassed.

Not Available

The following are not available in workflow functions. Move this logic to step functions instead.

  • Node.js core modules: fs, path, http, https, net, dns, child_process, cluster, os, stream, crypto (Node.js version), etc. See node-js-module-in-workflow.
  • Global fetch: Use import { fetch } from "workflow" instead. See fetch-in-workflow.
  • Timers: setTimeout, setInterval, setImmediate, and their clear* counterparts. Use sleep() instead. See timeout-in-workflow.
  • Buffer: Node.js-specific API. Use Uint8Array with toBase64() / fromBase64() / toHex() / fromHex() for binary data encoding, or atob() / btoa() for string-based base64.