Code
execute({ code }) runs your JavaScript on OpenBelt as you, with the workspace in reach as workspace. Send a
body that awaits and returns what you want back:
const [found] = await workspace.search("rsvp to a meetup")
const done = await workspace.apps.meetups.fn.rsvp({ event: "intro" })
const { docs } = await workspace.apps.meetups.collection("rsvps").list({ limit: 100 })
return { found: found.path, done, rsvps: docs.length }
What workspace has
workspace.search("words")finds functions (with their signatures), collections and connection tools;workspace.describe("<path>")says how to call one. Names can't be listed, only searched.workspace.apps.<app>.fn.<name>(input): a run, ascall_functionmakes one.workspace.apps.<app>.collection(name):list,get,add,set,update,delete, as the collection tools do.workspace.connections.<connection>.<tool>(input), asconnection_callwould.workspace.me(): you.- A name that isn't a JavaScript identifier (a dash, a leading digit) goes in brackets:
workspace.apps["hourly-joke"].fn.create_joke(input),workspace.connections["cmp-deepwiki"].ask_question(input).searchanddescribeprint paths that way, anddescribetakes either form. fetchreaches only the workspace's app hosts, as an outside sender would: to test a webhook end to end, sign a body withcrypto.subtleand POST it.Promise.allruns calls at once, to test contention.preview: "<env>"uses the apps deployed there, on its data.
Code has no app, secrets or network of its own: what an app needs every time belongs in a function.
For imports and seed data, use collection_add batches instead of looping over add here.
See Importing documents over MCP.
Limits
60 seconds, 300 workspace calls, 100 KB of code; a result over 24 KB of JSON comes back cut. An error
has kind (syntax, runtime, timeout, limit, sandbox), message and the line of your code.
Source: docs/code.md on GitHub