Skip to main content
Copy any block into a file, run it with ff, check the output. Each entry names its source guide for the full walkthrough.

Permissions

Fairyfly is deny-by-default, so the run commands below carry the smallest --allow-* set each snippet needs. Add a grant when you add an API; a missing one fails closed with PermissionDenied / PERMISSION_DENIED.
  • Loading code is not a read: import, Worker scripts, ff.json plus its main, and ff test files need no --allow-read.
  • process.argv is not environment access. Reading process.env.NAME needs --allow-env=NAME; an ungranted name reads as undefined, not an error.
  • --allow-run and --allow-ffi are trust-equivalent to full process access. Neither confines the code it enables.
  • --allow-all is not used below. It exists for fully trusted runs and the repo’s full test suite.
Permissions are an in-process policy layer, not an OS sandbox. Full model: Permissions.

Hello, world

No native API, so no grants. Guide: Quickstart.

HTTP server

http.serve always binds 0.0.0.0; --allow-net=127.0.0.1:3000 does not match the listener. Routing, JSON REST API, SQLite-backed notes API: HTTP Server guide. Method/options tables: http API.

Fetch client

Ports matter: example.com:443 covers only HTTPS on 443. Use --allow-net=example.com to allow any port, or a bare --allow-net to allow every host. POST JSON, redirect rules, private-CA trust, mirror script: Fetch Client guide. Types and readers: fetch API.

WebSocket chat room

The server needs the listener scope. A separate ff client needs --allow-net=127.0.0.1:3000 (or localhost:3000); browsers are outside the runtime’s permission policy. Upgrades are automatic when the websocket block is present — no handler branch. Presence counter, binary frames, client API: WebSocket guide.

TLS + WSS

The CLI reads --cert / --key before the runtime, so those paths need no --allow-read. A tls: { cert, key } object inside the app is a runtime read and does:
Dev certs, self-trust cases, WSS echo: TLS guide. ALPN negotiation: HTTP/2 guide.

SQLite notes API

--allow-write=. is required even though only notes.db was named: SQLite creates notes.db-wal and notes.db-shm beside it. The read scope covers the database file; the directory write scope covers the siblings. Transactions, lastInsertRowId(), busy timeout: SQLite API.

Workers (hash offload)

No flags: loading hasher.js is a program-loading carve-out. The worker inherits the parent’s policy, so a worker that calls fs.readFile needs the parent to hold --allow-read. Spawn rules, { data } vs workerData, terminate, pool pattern: Workers guide.

Packages (markdown blog)

ff init and ff imprint are CLI operations, not runtime APIs — no permission flags. Imports from installed packages load as program files. The server needs only the listener scope. Install/remove/rebuild/CI: Packages guide. Resolution rules: Modules guide.

Testing a JSON endpoint

The grant applies to every test file in the run. Loading test files needs no --allow-read; reads inside a test do. Both net scopes are required here: 0.0.0.0:3902 for the listener and 127.0.0.1:3902 for the client. check/done, server fixtures, run.sh: Testing guide.

Bytecode ship

ff compile is a CLI operation and needs no flags. Bytecode carries no policy: ff app.ffbc needs the same grants the source needed — for example --allow-net=0.0.0.0:3000 for a server. When to compile, caps, stripped traces: Bytecode guide.

Timers + process CLI

poll.js needs the outbound net scope. tool.js reads only process.argv, which is not gated; if it read process.env, that would need --allow-env=<NAME>. Sleep, intervals, unref, microtasks: Timers guide. argv/env/exit: Process guide. Env vars: Env guide.

Blobs and forms

The blob is in-memory, so no --allow-read. If you load the upload with fs.readFile, add --allow-read for that path. slice, round-tripping, file-drop endpoint: Blob and FormData.

Deploy checklist

FF_ECHO is runtime configuration, not app env, so it needs no --allow-env. If the app reads PORT, add --allow-env=PORT and make the net scope match that port. The policy lives in the start command, not ff.json. Docker, ff start, production TLS, health endpoint: Deploy guide. Install paths: Installation. Caps: Limitations.

See also