Skip to main content
Functions let tenants deploy real Python business logic on the SnackBase instance—HTTP-invocable, secret-aware, and dependency-capable—without a separate backend.

Positioning

Invoke URL

Optional path suffix is supported: /api/v1/f/{account_slug}/{slug}/sub/path. auth_required defaults to true (JWT / API key for the same account). Public webhooks set auth_required=false.

Handler contract

Async handlers are supported. Baseline packages in every env: snackbase_fn and httpx.

Dependencies

Declare exact pins on deploy (openai==1.66.0). Unpinned names, ranges, and git/URL installs are rejected. The server runs uv at deploy time; invoke is offline (no PyPI on the hot path). Installing a package can execute code on the host, so deploys are fail-closed by default:
  • SNACKBASE_FUNCTION_DEPENDENCY_MODE defaults to allowlist. Only packages named in SNACKBASE_FUNCTION_DEPENDENCY_ALLOWLIST install; anything else is rejected with HTTP 400. Set the mode to open_pinned to accept any pinned PyPI package — that lets any account admin install arbitrary packages on the instance.
  • Pins install from wheels only (--only-binary), so a source distribution’s build backend never runs. A package with no wheel for the runtime platform fails to deploy.
  • The install subprocess runs with a scrubbed environment: it inherits proxy, CA and cache settings but never the server’s SNACKBASE_* secrets.

Invoke sandbox

Each invocation runs in a subprocess the kernel confines:
  • Filesystem — Landlock restricts the child to the interpreter, its own function env (read-only) and its per-invoke work directory (read-write). Other tenants’ envs, sb_data/ and the database file are unreachable. Landlock needs no extra container capabilities and no seccomp exemption, but it does need Linux 5.13+.
  • Resources — setrlimit bounds address space (SNACKBASE_FUNCTION_MEMORY_LIMIT_MB, default 512), CPU time and open file descriptors, on top of the existing wall-clock timeout.
  • Egress — the SSRF policy is applied at socket.connect, so it covers raw sockets and not just httpx/urllib.
SNACKBASE_FUNCTION_SANDBOX_MODE controls this: On a kernel without Landlock — including macOS development machines — auto runs handlers unconfined and logs a warning at startup. A production deployment on such a kernel refuses invokes rather than degrading silently.

Dual client

Encrypted collection fields stay redacted unless the function has both:
  • grant records.secrets.read:<collection>
  • API-key scope records:secrets:read

Secrets

Function secrets are Fernet-encrypted, write-only on list, and injected as env vars into the child process. Names cannot start with SNACKBASE_.

Isolation & limits

  • Per-version venv + python -I subprocess
  • Timeout kill (default 30s) → HTTP 504 / status timeout
  • Per-account and global concurrency caps → 429
  • SSRF egress policy: deny loopback, RFC1918, link-local, metadata, ports 25/587
  • Nested invoke budget via X-Function-Depth

Management API

Manage mutations require account admin (or functions:write / secrets:write scopes).

Automation

Hooks, Workflows, and Custom Endpoints support action type invoke_function:

SDK & CLI

Admin UI

Instance Admin → Functions (instance Admin only; not hosted in Cloud Console):
  • Code tab — CodeMirror multi-file Python editor with line numbers, syntax highlighting, search, and folding. Switching files keeps each file’s content, cursor, selection, scroll position, and undo history.
  • File rules — Relative POSIX paths only (for example utils.py, lib/formatters.py). Absolute paths, .. segments, backslashes, empty names, and names longer than 255 characters are rejected in the UI and again on deploy.
  • Entrypoint — Marked with ★. Use Set as entrypoint before removing the current entrypoint file. At least one source file is required.
  • Dependencies panel — Exact pins (package==version) are the source of truth. The editor always generates a read-only requirements.txt from that list (including an empty file when there are no pins). Do not edit requirements.txt in the Code tab.
  • Deploy is save — Source is persisted only when you deploy. A successful deploy creates an immutable Function version and clears the unsaved-changes indicator. Leaving or reloading with local edits prompts for confirmation; un-deployed edits exist only in the browser session and can be lost if you confirm leave.
  • Syntax preflight — Deploy parses every .py / .pyi file before installing dependencies. Syntax errors return HTTP 400 with file, line, and column. Invalid imports still pass preflight; handler-contract checks remain on test/invoke.
  • Also: test sheet, executions, versions/rollback, grants, and secrets.
There is no Python language-server / IntelliSense and no SQL query editor in this surface. The shared editor shell is language-adaptable for a future SQL Editor (dialect + collection schema completion) without replacing Function deploy or dirty-state behavior.