Dynamic Functions
Your own serverless JavaScript, running inside your workspace.
Dynamic Functions are your own serverless JavaScript, running securely inside your Portablemind workspace. They let you extend the platform without deploying any infrastructure: pull data from external APIs, transform records, run scheduled jobs, or react to things happening in your workspace — all from a code editor in the app.
Each function executes in a sandboxed runtime that is isolated to your workspace, with a configurable timeout, so experiments can't run away from you.
You'll find them in AI Studio, under Advanced / Dev → Dynamic Functions. Create one with New Function, or bring one in with Import Dynamic Function (functions export and import as JSON, which makes them easy to share between workspaces).
Writing a function
A function is plain JavaScript. Two things are in scope when it runs:
params— the input parameters passed by whoever invoked the function.context— runtime context, includingcontext.config(the function's own configuration object) andcontext.oauth.accessToken(an access token, when a shared OAuth configuration is connected — see below).
The editor starts you with a working template, and the value your code produces is returned to the caller. Each function has a Timeout (seconds) setting that caps how long a run may take.
Running functions
There are three ways a dynamic function runs:
- Manually — the Execute (manual run) action on the function's row runs it on demand with parameters you supply. Great while developing.
- On a schedule — configure recurring runs directly on the function: every N minutes, every N hours, daily at a set time, monthly on a day of the month, or a raw CRON expression for anything more exotic. Scheduled runs execute as the user you pick in Run As User, and the Active toggle turns the schedule on and off.
- On platform events (callbacks) — attach the function to a Callback Model and Callback Event so it fires automatically when that kind of record changes in your workspace, turning functions into lightweight automation hooks.
Every run is recorded — the Execution history action shows past runs with their results, so you can see what a scheduled or callback-driven function has been doing.
Connecting to external services (OAuth)
Functions that call external APIs can use a Shared Configuration (OAuth) — a workspace-level OAuth connection to an outside service. Once connected, your code receives a ready-to-use context.oauth.accessToken, so you never handle client secrets or token refresh yourself. This is the pattern for integrating accounting systems, CRMs, and other third-party APIs.
Dynamic functions and AI
Dynamic functions plug into the rest of the platform:
- AI agents can list and execute your dynamic functions as tools, which means you can hand an agent a custom capability just by writing one.
- Combined with schedules and callbacks, a function can feed fresh external data into the workspace that your agents and AI memory then work from.
Tip: If a capability is mostly instructions for an agent, package it as a skill; if it's mostly code that needs to run reliably (API calls, data transforms, scheduled jobs), make it a dynamic function. The two compose well.
For the underlying API — managing and executing functions programmatically — see the API guide.