stackyapper_run_code. Instead of
calling tools one at a time and reading every response, the client writes a
short JavaScript script. The script calls your connected apps, filters and
combines the results, and returns only the summary. One code-mode run can
replace a dozen tool calls, and the model reads kilobytes instead of megabytes.ok: false. If code
mode access is removed, the run stops and its result is withheld.async function. Use await and end with
return. The returned value, converted to JSON, is the result. A script pasted
inside a single Markdown code fence is accepted as-is.tools object:| Call | What it does |
tools.search({ query }) | Find tools by describing the task. |
tools.schemas({ tool_names }) | Get the exact arguments for tools you found. Each schema includes a TypeScript-style signature. |
tools.connections({ service }) | List connections for an app when there is more than one. |
tools.call({ tool_name, arguments, connection_id }) | Run a read tool. connection_id is only needed when an app has several connections. |
ok:123456const result = await tools.call({ tool_name: 'cw_get_ticket', arguments: { ticketId: 42 } }); if (!result.ok) { // result.error = { code, message, retryable } return { ticket: null, unavailable: result.error.message }; } return { summary: result.data.summary, status: result.data.status?.name };
{ ok: true, data }: data is the tool's result.{ ok: false, error: { code, message, retryable } }: the call failed, but
the script keeps running. Treat that source as unavailable, not empty.tool_unavailable (the tool doesn't exist or isn't
available to you), tool_call_timeout (the app didn't answer in time), and the
app's own error codes.tools.schemas returns each tool's JSON Schema plus a compact signature, for
example:12(args: { after?: string; pageSize?: number; sourceType?: string }) => { alerts: unknown[]; pagination: { next_page_token: string | null; complete: boolean; upstream_count: number; returned_count: number } }
?. Don't invent tool names or arguments. Search,
then read the schema.console.log, info, warn, error, and debug work. Output is returned
with the result, including when a script fails, which makes a failed script
easy to fix. It is never stored.pagination object. Keep calling with
next_page_token until it is null, and say whether you got everything:123456789101112131415const alerts = []; let after; do { const page = await tools.call({ tool_name: 'ninja_list_alerts', arguments: after ? { pageSize: 100, after } : { pageSize: 100 }, }); if (!page.ok) return { counted: alerts.length, complete: false, error: page.error.message }; alerts.push(...page.data.alerts); after = page.data.pagination.next_page_token; } while (after); const bySource = {}; for (const alert of alerts) bySource[alert.sourceType] = (bySource[alert.sourceType] ?? 0) + 1; return { total: alerts.length, complete: true, bySource };
123456789101112const [tickets, alerts] = await Promise.all([ tools.call({ tool_name: 'cw_search_tickets', arguments: { conditions: 'closedFlag=false AND priority/name contains "Priority 1"', pageSize: 50 }, }), tools.call({ tool_name: 'ninja_list_alerts', arguments: { pageSize: 100 } }), ]); return { openP1Tickets: tickets.ok ? tickets.data.length : null, activeAlerts: alerts.ok ? alerts.data.pagination.upstream_count : null, unavailable: [tickets, alerts].filter((r) => !r.ok).map((r) => r.error.message), };
Promise.all, and every call must be
awaited before the script returns. Matching records across apps needs a shared identifier. Names that look alike
are not proof that two records are the same company or device.| Limit | Value |
| Script size | 16 KiB |
| Tool calls per run | 12 (including search and schema calls) |
| Time per tool call | 20 seconds, always leaving 2 seconds for the script to finish |
| Time per run | 30 seconds |
| Tool results read per run | 1 MiB in total |
| Returned result | 64 KiB. Larger results are truncated and marked truncated. |
| Memory | 16 MiB |
| Runs at the same time | 2 per workspace |
| Runs per day | 500 per workspace, resetting at midnight UTC |
result_preview and says it is
incomplete.console output. Calls that already finished may have happened; nothing is
retried automatically.| Reason | What to do |
| The script failed at line N | Fix the error shown. Syntax errors are reported the same way. |
| More than 12 tool calls | Use larger pages or fewer searches. |
| Passed the 30-second limit | Make fewer or faster calls, or split the work into two runs. |
| Tool results passed 1 MiB | Request smaller pages or fewer fields. |
| Used its work budget or memory | Simplify loops over large results, or keep fewer values. |
| Returned before awaiting every call | await every tools call, or await Promise.all(...). |
| Code mode is busy in this workspace | Two runs are already in progress. Try again shortly. |
| Today's limit reached | The workspace has used its 500 runs for today (UTC). |