The entry function
A script exports one async function. The runtime calls it with a single object.
Notes on the shape:
- CommonJS is the norm:
module.exports = async (...) => { ... }.export defaultworks too, and an ESM file with top-levelawaitis loaded as a module. - A node with an input schema must destructure
args. Theasync (page) => { ... }form does not receiveargsand fails validation when the node declares inputs. - The return value decides output and routing. The golden path is to return
asteroid.handoff(...), which chooses the next node and carries its data. An object instead becomes output variables, a string becomesscript_output, and a throw is a failure. See Route to the next node yourself.
Timeouts
Inside that budget, Playwright actions carry their own defaults, kept short so a wrong selector fails fast instead of stalling.
Raise a limit for a genuinely slow step:
The sandbox
A script runs in the execution’s sandbox, next to the browser.- Node.js 22. Node built-in modules (
node:fs,node:path,node:crypto, and the rest) are available. - Playwright drives a headless Chromium over the live session. You get it through
page,browser, andcontext, so you do not launch a browser yourself. python3is present, withpython3-yaml, reachable from the workflow’s Bash tool.- No PDF or OCR libraries. To read a PDF or a print-only page, parse it in the browser page with
pdf.js, not with a Node module. See the PDF pattern.
The filesystem
The working directory is/home/agent. A script reads and writes files with node:fs, using absolute paths.
A script’s own file lives under
/home/agent/shared/<node-slug>/, where the runtime derives <node-slug> from the node’s display name. Because it re-derives the slug, a rename never breaks how the runtime finds the entry script. It does not, however, rewrite absolute paths you wrote by hand. A hardcoded /home/agent/shared/<node-slug>/... path (a required helper, a reference file) breaks when you rename the node, so update those yourself.
Workflow filesystem
The full directory layout, the quotas, and how files get in and out
Requiring modules
require('asteroid')is provided by the runtime. Its whole surface ishandoff(...),generateTotp(...),emit(...),requireConfirmation(...)andwaitForReply(...)with itsanswerSchemasbuilders and error classes. See Route to the next node yourself, Two-factor codes, Emit your own event, Pause for approval and Ask a question.- Node built-ins resolve normally.
- Helper modules must be required by their absolute path under
shared/, for examplerequire('/home/agent/shared/file_claim/lib/dates.js'). A relativerequire('./dates.js')does not resolve, because the runtime runs your script from a private copy that holds no sibling files. - Use absolute
/home/agent/...paths. They work exactly as written from the entry script. Pass a required helper the paths it needs as arguments, rather than letting it compute its own, so it never depends on where the runtime placed your script.
Secret tokens
A script fills a secret with a##ITEM_KEY.FIELD## token. The runtime replaces it from the
secret attached to the profile, just before the script runs, so the value never reaches the model.
The usage is in Secrets in a script, and the full
model is in Secrets & 2FA.
Two-factor codes
asteroid.generateTotp(secret, options?) returns the current authenticator code as a string. Pass
the token of a TOTP seed field. The runtime fills the token before the script runs, so the seed
stays inside the script run. Only the generated code reaches the page.
The secret may be a bare base32 seed or an
otpauth://totp/ URI. A URI’s own digits, period
and algorithm apply unless an option overrides them.
- A token the run does not fill throws, and the error names the token.
- An unusable seed throws a fixed message that never quotes the seed.
- Generate the code immediately before you submit it. If the site rejects it, generate a fresh code and retry once.
Emit your own event
await asteroid.emit(name, options?) publishes an event from inside the run. It reaches every
webhook and Slack integration on the workflow’s Notifications tab that subscribes to
Custom Event, either every custom event or those whose name matches a filter. The script
holds no token and no URL.
Files are sent by reference. The runtime uploads each one before the event goes out, and the
event carries a signed download link that works for one hour. Slack shows an image inline and
any other file as a link. A webhook gets the link in
files[]. A file under shared/ cannot be
attached: that directory is read-only and never synced from a run.
- Await the call. It resolves to
{ id }. Delivery to your endpoint happens after that, so a slow or failing endpoint never fails the script. - A malformed call throws, and the error names the argument. So does the 101st emit of one execution.
- Do not send an event again after “did not confirm”. That error means the runtime gave no
answer in time. The event can still arrive, and a second call is a second event with a new
id. - A secret never leaves the run. If
textorpayloadcontains the value of a secret from the profile, the runtime swaps it for its'##ITEM_KEY.FIELD##'placeholder before the event is sent, so the receiver sees the placeholder, not the value. Anameor a file path that contains a secret value is refused. File contents are sent as written. - A test-run in Astro sends nothing. It checks the call, logs the event, and resolves to
{ id: null, dryRun: true }. - Do not use it for the final result. A run that fails, is cancelled or times out never reaches
your
emit.EXECUTION_COMPLETED,EXECUTION_FAILEDandEXECUTION_CANCELLEDalways fire. Useemitfor progress and for content the lifecycle events do not carry.
Pause for approval
await asteroid.requireConfirmation(message) pauses the run at that line until a person approves
it. Put it right before a submit, so the user approves a filled form, not an empty one. The run
goes to awaiting_confirmation, and the execution page shows message, the live browser and the
approval controls. The browser, the page and the script keep their state while they wait.
- Await the call. Without
await, the script runs on to the submit. messageis 1 to 500 characters. Say what the user approves.- One confirmation at a time. A second call while one waits throws.
- It works in a script the node runs itself. A script the agent runs during an AI turn gets an error at the call.
- A test-run in Astro stops at the call. It logs the message and throws, so a test never submits. Run the workflow to see the pause.
- A rejected step is not a script failure. The run shows as cancelled by the user.
Ask a question
await asteroid.waitForReply({ id, question, schema }) pauses the run at that line until a person
answers, and returns the answer. The answer always matches schema: the platform checks it before
the script sees it. The run goes to paused_by_agent. The browser, the page and the script keep
their state while they wait.
It returns
{ answer }, or { freeText } when the person typed free text. actor is added only
when an API key or a service answered. It is absent for a person, who may be Asteroid staff, since
a script is customer code.
An option is a string, or
{ value, label?, description? }. Every builder also takes title and
description. A builder throws when a lower bound is above its upper bound, such as minLength
over maxLength, and on an option it does not list, such as text({ pattern }): nothing would
check it. A schema you write by hand is checked by the platform when the question is asked. It
refuses any keyword outside the six types, pattern included, and the call throws with the
platform’s message.
A person answers on the execution page, or with
asteroid execution answer <execution-id> --question-id <id> --answer '<json>'.
- Await the call. Without
await, the script runs on without the answer. - An error you do not catch fails the script, so the node’s failure action decides what happens.
- One question or confirmation at a time. A second call while one waits throws.
- Pause is refused while the run waits. The run is
paused_by_agentuntil the answer. Cancel still ends it. - It works in a script the node runs itself. A script the agent runs during an AI turn gets an error at the call.
- A workflow run waits at the call until the wait ends, as the table above says.
- A test-run in Astro stops at the call. Running the script with
browser_run_node_scriptchecks the options, logs the question and throws. Nobody is asked. Run the workflow to see the pause.
Related
Script a step
Attach a script, route from it, and pin its inputs
Workflow filesystem
Directories, quotas, and file transfer
Secrets & 2FA
How a
##ITEM_KEY.FIELD## token gets its valueNodes
Where a script file lives on a node

