# javascript.script.run

Runs JavaScript in a sandbox and adds what it returns as script

# javascript.script.run

```
javascript.script.run → script
```

Runs JavaScript in a sandbox and adds what it returns as `script`. The body after `--` is the function body of `async function(input, n, ctx)`, and whatever it `return`s is added to the payload as `script` — the rest is kept, so the next node reads `input.script.x`. `input` is the current payload (right after a webhook, `input.webhook.body.x`; the request anywhere, `$trigger.body.x`); `ctx.trigger.params/query/auth` is the request and `ctx.nodes.<id>` an earlier node's output. It cannot set a status or header ([`web.response.send`](/nodes/web/web.response.send.md) does), `return null` does not stop the run ([`logic.if`](/nodes/logic/logic.if.md) does), and `fetch`, `setTimeout`, `require` and `import` are blocked ([`http.response.fetch`](/nodes/http/http.response.fetch.md) calls out). Keep it to shaping data: compose, rename, compute — a run has 1 s and its return 256 KB (`DenoSandboxError: timeout exceeded` means do less here or split the work). A `__signal` key in the returned object is stripped and shown as live progress in the Studio; `__zf_files` stores files for the run.

## Examples

### Shape rows for a page

```
| javascript.script.run -- "return { posts: input.query.rows.map(r => ({ ...r, when: r.created_at.slice(0, 10) })), total: input.query.row_count }"
```

The next node reads `input.script.posts`.

Input:

```json
{
  "query": {
    "rows": [
      {
        "title": "Hi",
        "created_at": "2026-09-13T04:00:00Z"
      }
    ],
    "row_count": 1
  }
}
```

It answers:

```json
{
  "query": {
    "rows": [
      {
        "title": "Hi",
        "created_at": "2026-09-13T04:00:00Z"
      }
    ],
    "row_count": 1
  },
  "script": {
    "posts": [
      {
        "title": "Hi",
        "created_at": "2026-09-13T04:00:00Z",
        "when": "2026-09-13"
      }
    ],
    "total": 1
  }
}
```

### Combine two earlier nodes

```
| javascript.script.run -- "return { user: $nodes.b.query.rows[0], orders: $nodes.c.query.rows }"
```

Anywhere in graph mode downstream of `b` and `c`: wired from both, it runs once, when both have answered (each `$nodes` reference names an upstream node of this pipeline by a literal id; a computed `$nodes[name]` is refused at save).

## Used in

- [Agentic Scheduling (AI + Cron)](/examples/agentic-scheduling.md)
- [Auth and Authorization](/examples/auth-and-authorization.md)
- [Blog with Admin](/examples/blog-with-admin.md)
- [Cookie + JWT Authentication](/examples/cookie-jwt-auth.md)
- [Forum with Real-Time Chat](/examples/forum-with-chat.md)
- [Sign in with Google (OAuth login)](/examples/oauth-login-google.md)
- [Real-Time Game (WebSocket State Sync)](/examples/realtime-game.md)
- [Web Scraping + Data Pipeline](/examples/scraping.md)
- [Static Entry Generation](/examples/static-entry-generation.md)
- [TTS API + Frontend Page](/examples/tts-with-page.md)
- [Webhook → TSX Page](/examples/webhook-page-tsx.md)
- [REST API + PostgreSQL](/examples/webhook-restapi-postgres.md)
