Guide Plugins
How plugins run
A plugin never runs inside the app or its engine. Each plugin gets its own Node process, started when one of its contributions is first needed, talking to the engine over the process’s IPC channel, and limited to what the person who installed it allowed. This page explains that process, the limits on each operating system, and how to test a plugin.
The plugin’s process#
- Started on first use. The first call to a plugin starts its process on the same Node the engine runs on (inside the app, the app’s own copy of Node), waits for it to load the plugin’s entry, and checks what the module exports against
plugin.yaml. A manifest that names a contribution the code does not export, or the other way round, is an error that names it. - Each call gets its own temporary folder (
ctx.tempDir), removed afterwards. - Stopped when idle. A process with nothing to do for a minute is stopped; the next call starts it again.
- Cancelling a step, a run or a preview aborts
ctx.signal. If that call was the only one running, the process is killed at once. - Time limits. A call that takes longer than five minutes is stopped and fails with “took longer than”. A process must start and load within 20 seconds.
- Crashes. If the process dies under a call, that call fails with “stopped unexpectedly”, and the next call starts a fresh process. After three crashes within a minute, the plugin is not started again for a minute. Settings › Plugins shows “Stopped unexpectedly last time” and when.
- Memory. Each process has a memory cap (1 GB by default).
- Environment. The process gets a scrubbed environment: no secrets or tokens from the app’s own environment.
How tables cross#
Tables go to and from the plugin as JSON lines in the call’s folder, every value as its exact text, so no digit is lost on the way: a decimal arrives as a Decimal, a date as a DateOnly, a date-time as a Timestamp that keeps microseconds, an empty cell as null. The engine’s own hidden columns (row ids) never reach the plugin, but the rows a check names as failing are matched back to them, so “show rows” opens the right rows. The full list of types is in Tables and values.
A step that can be SQL should give compileSql: its SQL then runs inside the engine’s own query, nothing crosses to the plugin’s process, and the step shows its SQL in the SQL tab like any built-in step. That SQL is one SELECT over the step’s inputs by name (input, input2, …) and nothing else: no files, no table functions, no other tables. The engine refuses anything that reaches past its inputs.
Capabilities and the sandbox#
A plugin’s process starts with:
- read access to the plugin runtime, its own folder, its data folder (
ctx.dataDir, for files it keeps between runs) and the call’s exchange folder; - write access to its data folder and the exchange folder only;
- no network;
- no child processes, worker threads, native add-ons or WASI.
capabilities in plugin.yaml asks for more: network, filesystem (read and write files anywhere you can), process (start other programs). The install dialog explains each one in plain words, and they are granted only when the person installing ticks “I trust … with this access”. Only confirmed capabilities are switched on in the process. The words are in Capabilities.
How the limits are enforced depends on the operating system:
| Files | Network | Other programs | |
|---|---|---|---|
| All systems | Node’s permission model (--permission): reads and writes only the folders above |
Switched off inside the process by the runtime | Refused by Node’s permission model |
| macOS | Also sandbox-exec, which keeps writes to the data and exchange folders |
Also denied by sandbox-exec from outside the process |
|
| Linux | Also bwrap (bubblewrap) when installed: the file system read-only except the data and exchange folders |
Also a separate network namespace (bwrap, or unshare when bwrap is not there) |
|
| Windows | Node’s permission model only | Inside the process only |
On Windows, and on Linux without bwrap or unshare, the network limit is enforced only inside the plugin’s process, not by the operating system. A plugin that asks for filesystem and network together runs without an operating-system sandbox. A capability the plugin did not declare cannot be granted at all.
What a plugin may not do is reported in its own words when it tries: a refused file read or write, connection or program names what was refused.
Versions#
The runtime speaks a protocol version (PLUGIN_API_VERSION); the app refuses a plugin built for a newer one. requires in the manifest (such as >=1.0) says which app versions a plugin works with; an app that is too old says so instead of installing it.
Testing a plugin#
Call the functions directly#
definePlugin returns the definition unchanged, so a contribution is a plain object whose functions you can call in any test runner. Give it a table and a context:
import assert from 'node:assert/strict';
import plugin from '../index.mjs';
const ctx = {
signal: new AbortController().signal,
pluginDir: '.', dataDir: '/tmp', tempDir: '/tmp',
log: () => {}, progress: () => {},
};
const table = { columns: [{ name: 'Title', type: 'text' }], rows: [{ Title: 'Crème brûlée' }, { Title: null }] };
const rows = await plugin.steps.slugify.transform({ column: 'Title', into: 'Slug' }, [table], ctx);
assert.deepEqual(rows.map((r) => r.Slug), ['creme-brulee', null]);
Run it with node --test from the plugin’s folder. To resolve @gridkiln/plugin-api outside the app, add the package to the folder’s devDependencies, or test the functions in a file that does not import it.
Serve it as the app does#
servePlugin(definition, transport) runs the same loop the plugin’s process runs, over any transport with send and onMessage, so a test can send plugin.hello, step.transform and the other protocol methods exactly as the engine does, with tables as JSON-lines files written by writeExchangeTable. The plugin API’s own tests (packages/plugin-api/test/runtime.test.ts) do this with an in-memory transport pair, and are a good starting point.
Try it in the app#
- Put the plugin’s folder in a test project’s
plugins/folder, or install it with Settings › Plugins › Install plugin… › This project. Settings › Plugins lists any problem with the manifest, one sentence each. - Use a contribution in a small pipeline (see Using a plugin’s contributions). The step’s preview and impact line show what it does on the real data; its errors show in the step card, with the plugin’s own message for a
PluginErrorand the stack under Details for anything else. - Run the pipeline from the command line to see the whole run:
gridkiln run <project> <pipeline> --verboseprints the engine’s own log lines as well, andgridkiln checkevaluates the checks without writing anything. A plugin’s ownctx.loglines are shown with its errors.
The engine’s own plugin tests (packages/engine/test/plugins/) install the example plugins in fixtures/plugins/ into a temporary project and run them through real processes, including misbehaving, which tries every forbidden thing once.