Skip to content

Write and run a script

Goal: run a small TypeScript or JavaScript program against the active context — read lists, filter them, act on many items — through the operation catalog (vf).

Prerequisites

  • Signed in. Reads work for everyone; writes need an admin.
  • The context to run on is active (the run button names it); on a protected context each write asks first.

Steps

  1. Open Config > Scripts (route /config/scripts).
  2. Start from an example: under Examples, click Stopped workers. The code appears in the editor (with an empty name).
  3. Edit it. The operations you can call are listed under Operations (expand a group); catalog with input schemas opens the full catalog. For example:

    const workers = await vf.workers.list()
    const stopped = workers.filter(w => w.status !== 'RUNNING')
    for (const w of stopped) print(w.status, w.name, w.id)
    return { stopped: stopped.length, total: workers.length }
    
  4. Name it and Save (e.g. stopped-workers). It appears under Yours (kept in this browser).

  5. Run on <context>. While it runs the button is Stop.
  6. Read the result: Output has what it printed and the returned value as JSON (or done); Operations called lists each call, ✓ or ✗, with its input, writes marked.
  7. Writes: a call such as await vf.workers.stop({ id }) passes the write gate: on a protected context the dialog asks (a yes covers the writes of the next 5 s); a No makes that call throw.

What you should see

  • Output lines as the script prints; the result at the end; errors in red.
  • Each write in Infra > Changes.

Troubleshooting

Symptom Cause and fix
does not compile: … A syntax error; types are allowed, imports are not.
no operation <name> A misspelt vf.<group>.<action>: check the Operations list.
<operation>: /<field> … The input does not match the schema; the message names the field.
fetch fails / no network By design: the sandbox has no network. Reach the platform through vf only.
only admins may write You are not an admin.
stopped after 10 minutes The time limit: split the work, or read with smaller timeoutMs.
The script is gone in another browser Scripts are kept per browser (localStorage); copy the code over.

More: Scripts.