Skip to Content

Sandbox and limits

How Floor runs a deployed backend: its systemd sandbox, memory and CPU caps, outbound allow list, idle stop and wake, migrations and logs.

This page explains what a deployed backend can and can't do on Floor's server, and the floor.toml keys that set its limits. Read it before you write code that touches the filesystem, calls other services, or needs more than the default memory.

A backend runs as a plain process, with no container. Each deployment is one instance of a fixed systemd unit, floor-app@<deployment>.service, which Floor starts and stops. On a laptop without systemd, Floor runs apps as plain child processes with none of these limits.

The sandbox

Every backend gets the same sandbox:

  • Its own user. A throwaway user made for this unit (DynamicUser), with no home folder.
  • A read-only system. Everything outside its own private /tmp is read-only. The release's files are mounted read-only at /app, which is the working directory.
  • No devices, no new privileges. No capabilities, no setuid, a system-call filter for ordinary services, and only Unix, IPv4 and IPv6 sockets.
  • At most 256 tasks (processes and threads).
  • Its variables in a file only systemd reads, not the app's user.

So:

  • Keep state in Floor, not on disk. Rows go in the database (cx.db()), small values in key-value (cx.kv_set), files in blob storage (Files). /tmp is private to one deployment and goes when it stops.
  • Don't rely on what the server has installed. A backend's release holds its binary and nothing else, so data files it needs belong in the binary (include_bytes!), the database or blob storage.

The engine's socket (/run/floor/link.sock) is mounted in, which is how Cx reaches Floor: triggers, KV, commands, messages and the rest go over it, not over the network.

What the backend gets

Variable
PORTthe port to serve HTTP on, on 127.0.0.1; the gateway sends requests here
FLOOR_PROJECTthe project, e.g. sac or sac-staging
FLOOR_ENVIRONMENTproduction, or the environment's name (staging)
FLOOR_DEPLOYMENTthis deployment's id
DATABASE_URLthe project's database, when it has one (unless a variable sets it)
FLOOR_LINK, FLOOR_LINK_TOKENthe engine's link and this deployment's token
your variableseverything set with floor deployments set-var for this environment

floor::run reads these for you. See Deploy a backend for setting variables.

Memory and CPU

[backend]
mount = "access-control.example.com/api"
memory_mb = 128      # default 256
cpu = 0.5            # cores, default 1
  • memory_mb becomes systemd's MemoryMax. A backend that goes over it is killed, and systemd starts it again after 2 seconds.
  • cpu becomes CPUQuota: 0.5 is half a core, 2 is two. A busy backend is slowed down to it, not killed.

The migration step runs under the same caps.

Outbound: the hosts it may reach

By default a backend may reach anywhere. List hosts to allow only those:

[backend]
mount = "street-lights.example.com/api"
outbound = ["api.github.com", "10.20.0.0/16"]
  • What counts. Host names, IP addresses and CIDRs. Localhost and the server's name servers are always allowed, so the database and DNS keep working.
  • How it works. systemd filters by address (IPAddressDeny=any plus an allow list). Host names are resolved when the backend starts, so a host that moves to new addresses is reached again after the next restart or deploy.
  • Ports aren't limited. Only addresses are.
  • Floor's own services don't need it. Messages, AI, blob URLs, device commands and the rest go through Cx over the engine's socket. Only your own HTTP clients (reqwest, or any) need outbound, including a backend that fetches a signed blob URL itself: list Floor's file host then.
  • The deploy log says so. It shows Outbound only to api.github.com, 10.20.0.0/16. On a laptop without systemd nothing is limited, and the log says that instead.

Idle: stop when quiet, start on the next call

[backend]
mount = "staging.access-control.example.com/api"
idle = "15m"

With idle, Floor stops the backend after that long with no request through the gateway and no trigger from the engine. The next request or trigger starts it again:

  • A request waits until the backend answers its health path, then goes through. Starting a sleeping backend took about 0.7 seconds in Floor's tests.
  • Triggers wait too. A trigger also starts it, and the engine keeps triggers until it's back.
  • Ticks don't count. An #[every] tick doesn't keep it awake, and a sleeping backend's ticks are skipped.

Use it for staging environments and quiet tools, not for a backend whose ticks must run.

Migrations: floor-migrate@

Before a new version starts, Floor runs its migrations once as a step of the deploy:

  • Where. <backend> --migrate, in floor-migrate@<deployment>.service: the same sandbox, caps and variables as the backend itself.
  • How long. Up to 10 minutes.
  • What you see. Its output goes to the deployment's log: each migration applied (applied 0004 visit notes (sql, 12 ms)) and Migrated in 0.6 s.
  • If it fails. The deploy fails and the old version keeps serving. Fix the migration in a new file; a file that ran is never edited (Database).

Health checks, restarts and stopping

  • Going live. A new version must answer its health path (default /) with a status below 500 within 90 seconds. Otherwise the deploy fails, and the deploy log shows the backend's last 20 lines.
  • Crashes. If the process exits with an error, systemd starts it again after 2 seconds.
  • Stopping. On a swap or a stop, the backend gets SIGTERM, stops taking connections, finishes what's in flight (up to 30 seconds), then exits.

Logs

The backend's standard output and error go to the server's system journal, tagged floor-app-<deployment> (and floor-migrate-<deployment> for the migration step). Log with floor::tracing:

floor::tracing::info!(lane = e.lane_id, plate = %e.plate, "gate opened");
  • The level. FLOOR_LOG sets the filter; the default is info,sqlx=warn. Set it as a variable: floor deployments set-var sac FLOOR_LOG debug.
  • Where to read them. The console's Watch › Logs pages read the journal. The journal keeps at most 1 GB and 14 days.
  • During a deploy. The deployment's own log (its console page, or floor deployments show sac <id>) has every step, the migration output, and the last lines of a backend that didn't start.
  • While you develop. floor dev streams the log with a line per request and trigger (Dev loop).

Request limits

These belong to the framework, not the sandbox, and are set per route: a request body is at most 1 MiB and a handler has 60 seconds, unless the route says otherwise (#[post(can = "files:write", body = "20mb", timeout = "2m")]). See Routes.

On this page