# Run Script Tool

`execute_script` runs one JavaScript program in a sandbox against the `verdalia.*` workspace API.

## When to Use

Use this tool for batched, bulk, or mechanical work: building a workflow and wiring its nodes, creating a table and filling it, reading many rows and computing an answer. One call replaces the sequence of individual tool calls that would otherwise do it, and only the script's return value crosses the wire.

Use the individual tools for a single surgical edit. One `add_workflow_node` call is cheaper and clearer than a script that makes one.

This is a General tool, usable by compatible runtimes when its scripting group is explicitly
configured. The generic Tool Provider does not offer that group as a new picker choice. Inside a
workflow, use the `js_script` node when JavaScript should run as a deterministic step rather than
at the AI's discretion.

The `verdalia-scripting` skill carries the full API reference — every namespace, every method, its argument object, and what it returns. Load it before writing anything non-trivial.

## Parameters

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `script` | string | Yes | The program to run. Its `return` value is the tool result. Every `verdalia.*` call is async and must be awaited. |

`script` is the only parameter. The language is JavaScript, and every run gets the same 300-second ceiling. `language` and `timeout_secs` are refused, not ignored.

## The API

Methods are `camelCase` and argument keys are `snake_case`. Take every signature from the skill; the agent tool of the same name may take different arguments.

| Namespace | Methods |
|-----------|---------|
| `verdalia.tables` | `create`, `modifySchema`, `insert`, `upsert`, `query`, `getRow`, `list` |
| `verdalia.workflows` | `create`, `get`, `addNode`, `editNode`, `patchNode`, `connect`, `deleteNode`, `deleteEdge`, `frames`, `createFrame`, `updateFrame`, `deleteFrame`, `updateConfig`, `listNodeTypes`, `nodeDocs`, `execute`, `listExecutions`, `executionResults` |
| `verdalia.library` | `list`, `get` |
| `verdalia.jobs` | `list`, `overview`, `get`, `cancel` |
| `verdalia.usage` | `current`, `llm`, `workflows`, `workflowFailures`, `media`, `events` |

`verdalia.jobs` and `verdalia.usage` are off until a workspace grants them in the Scripting group's settings. `jobs.list` pages the workspace's runs of every kind (workflow runs, agent sessions, data migrations) with the Jobs views' filters, `jobs.overview` counts the same jobs in each state with their average and p95 run time, `jobs.get` reads one, and `jobs.cancel`, a write, stops one. `verdalia.usage` is read-only: each method returns what the Usage page's matching panel reads, given the same parameters, and the skill maps every panel of the Usage page to its call.

Differences from the tools: `tables.insert` takes real rows (`{ table_id, data }`), not JSON text, at most 1000 per call; no namespace deletes a table, its rows, a library item or a whole workflow, and none pins a version; `workflows.connect` takes `[node_id, socket]` pairs; `workflows.listExecutions` takes a `lookback` of seconds or an RFC3339 instant; `workflows.execute` returns the run's id and status, and `executionResults` reads what its nodes produced. The four frame methods match `list_workflow_frames`, `create_workflow_frame`, `update_workflow_frame` and `delete_workflow_frame`: the same arguments, results and refusals. Framing is visual only: no frame call adds, changes or deletes a node, and deleting a frame releases its nodes. `frames` returns `{ workflow_id, frames, unframed }`; the other three return `{ workflow_id, frames }`.

## Returns

| Field | Type | Description |
|-------|------|-------------|
| `success` | boolean | Whether the script ran to completion |
| `result` | any | What the script returned, whole, whatever its size. Returning nothing reads as `null`. To keep a result small, return only the part needed, such as a slice or only the fields used. |
| `error` | object | Present only when `success` is `false` |
| `warnings` | array[string] | Rejections nothing in the script handled. The run still succeeded. Absent when empty. |

### Failed

```json
{
  "success": false,
  "error": {
    "name": "Error",
    "message": "edge target 'summarise' is not in the graph",
    "stack": "...",
    "stopped": null
  }
}
```

`stopped` is set to `timed_out` or `cancelled` when the sandbox ended the run rather than the script throwing.

## Errors

A failing call throws an `Error`. Its message says what went wrong, and there is nothing else to read off it: a failure means the script's assumptions about the workspace were wrong, and it is reported to whoever ran the script rather than branched on inside it. A script that needs to know whether something exists queries for it instead of throwing and catching.

## Notes

- Only the methods a workspace granted exist. A namespace it granted nothing in is `undefined`, and reaching through it is a `TypeError`. The tool description lists the namespaces the workspace has.
- Reach is the scripting tool group's own configuration — `no_access`, `read_only`, `write_only`, or `read_write` per namespace. It is not derived from the other tool groups.
- `workflows.execute` counts as a write: a run has effects outside the workspace.
- Writes are attributed and metered exactly as the equivalent tool call is. A script has no quota-exempt path.
- `_` has exactly these helpers: `map`, `filter`, `reduce`, `groupBy`, `countBy`, `sortBy`, `uniq`,
  `uniqBy`, `flatten`, `flattenDeep`, `chunk`, `compact`, `first`, `last`, `sum`, `sumBy`, `mean`,
  `min`, `max`, `maxBy`, `pick`, `omit`, `get`, `set`, `keyBy`, `mapValues`, `isEmpty`, `isNil`,
  `cloneDeep`. `_` is not lodash; other helpers are `undefined`.
- The sandbox also has `dayjs`, `DateTime`, `Intl`, `Buffer`, `Ulid`, and `require('crypto')`.
  There is no network, no filesystem, and no other module loading.
- At most 8 host calls may be in flight at once. A wider `Promise.all` throws as the call over the ceiling is made.
- An endless loop and a never-settling promise are both stopped by the run's wall clock.
- One wall clock covers the whole run, host calls included: 300 seconds, always. It is the bound a runaway script hits, not a budget to tune.
- A run holds nothing workspace-wide: other tool calls in the workspace proceed alongside a script however long it runs. Writes wait only on another write of the same resource — one workflow, one table's schema, one row, one document — including the script's own, so a `Promise.all` writing one workflow serialises on it and the same calls across eight workflows do not.
