Skip to Content
Docs

APIs and backends

A backend usually needs more than one public URL: internal services, a database, background work, and protection from too much traffic. Here's how those fit together on Skiff.

Private services

Turn on Private service under a project's Settings → Access and it stops being reachable from the internet within seconds. The router answers as if it doesn't exist, no certificate is issued for it, and its previews are private too.

Calling one service from another

Every project has a stable internal address, shown on its overview. It works from your team's other projects, workers and jobs, stays the same across deploys, and spreads calls across replicas:

from another project
curl http://billing-api:8080/invoices

Traffic stays on your team's private network, and other teams on the server can't reach it. A project needs one deploy after upgrading Skiff for its internal address to work. Apps deployed with skiff deploy also need an up-to-date CLI, and their network comes from [deploy] in skiff.toml.

An internal address has no authentication of its own. Anything on your team's network can call it, so keep checking credentials in the service if that matters.

Rate limits

Set a limit under Settings → Access, in requests a minute per visitor. A visitor can use a minute's allowance in one burst, and it refills steadily. Past that they get a 429 with a Retry-After header, before the request reaches your app. Calls over internal addresses aren't counted.

A visitor is an IP address, or an IPv6 /64. If you put a CDN like Cloudflare in front of Skiff, all its traffic comes from a few addresses and would share one allowance, so set limits at the CDN instead.

gRPC

gRPC services work with no setting to change, including streaming. Clients connect over HTTPS as usual, and Skiff speaks plain-text HTTP/2 to your app, so have the server listen without TLS on its port. A service with no web page passes its deploy check by answering over HTTP/2. Set the project's port yourself if the image exposes more than one. gRPC calls count toward a rate limit like any other request, and over an internal address they go directly to the service.

Services that don't speak HTTP

For a game server, message broker or anything else over raw TCP, open a Public TCP port in the project's Settings, then redeploy. Skiff holds that port and forwards it to your app, so the address stays the same across deploys, and it counts your app as ready once its port opens. A deploy doesn't move open connections: they end when the old version retires, and clients reconnect to the new one.

For UDP, such as a game server, voice, WebRTC or WireGuard, open a Public UDP port in the project's Settings and redeploy. Your app listens on that UDP port, and Skiff opens the same number to the internet through its router. Each client stays on one version until it has sent nothing for two minutes, so a deploy moves new clients to the new version without dropping anyone mid-session. An app deployed with skiff deploy also lists the port in skiff.toml as udp_port under [deploy].

Public TCP and UDP ports start at 1024. Ports under that are for well-known services, like DNS on 53, so only the server's admin, an owner of the team that set Skiff up, can open one. Skiff's own ports, such as SSH, the web and the dashboard, can't be taken.

  • Your app sees connections coming from Skiff, not the client's address.
  • A connection that sends nothing in either direction for an hour is closed, so keep long-lived clients alive with pings.
  • You may also need to allow the port in your provider's firewall.
  • Connections aren't encrypted by Skiff, so use your service's own TLS and passwords.
  • UDP isn't supported yet.

The rest of a backend

  • Databases: managed Postgres (with pgvector or TimescaleDB if you like, and read replicas), MySQL, MongoDB, Redis and ClickHouse, with the connection URL added for you, all with daily backups. ClickHouse's URL, in CLICKHOUSE_URL, is its HTTP interface on port 8123, which its clients for Python, JavaScript and Go speak.
  • Migrations: a release command runs before each new version goes live, and a failure stops the deploy.
  • Background work: workers and scheduled jobs run from your app's image.
  • Real-time: WebSockets and server-sent events work. When a new version goes live, new requests go to it, and the old version keeps running until its open requests finish, for up to 5 minutes. Set drain_timeout under [deploy] in skiff.toml to change that (in seconds, up to 3600, or 0 to stop it straight away). After that, the app gets a stop signal and 30 seconds to exit, so clients holding a connection open longer still need to reconnect.

Read replicas

A Postgres database Skiff created can have up to three read replicas: copies that follow every write within a moment, for reads, reports and dashboards that shouldn't slow it down. Click Add replica on the database under Databases. A replica copies the data first, then shows how far behind it is.

Apps attached to the database get DATABASE_READ_URL beside DATABASE_URL on their next deploy. It's one address for all the replicas, and lookups are spread across the ones running. Replicas refuse writes, so write through DATABASE_URL and read through DATABASE_READ_URL when it's set:

const reads = new Pool({ connectionString: process.env.DATABASE_READ_URL ?? process.env.DATABASE_URL })
  • A replica can be a moment behind, so read what a request just wrote from DATABASE_URL.
  • Previews read from their own copy of the data, never from the project's replicas.
  • The database keeps up to 2 GB of history for a replica that stops reading. Past that, the replica shows it fell too far behind: remove it and add a new one.
  • Returning the database to an earlier time, or recovering it onto a new server, copies each replica again.
  • Replicas run on the same server. They spread the reading, but don't keep the database up if the server goes down.
  • Removing the last replica takes DATABASE_READ_URL away. Redeploy attached apps straight after, because until then they still try the read address.

Workers and jobs in skiff.toml

An app deployed with skiff deploy lists its workers and jobs in skiff.toml. Each deploy restarts the workers on the new version, and the dashboard shows them and runs the jobs on schedule, in the server's time zone.

skiff.toml
[[workers]]
name = "queue"
command = "node queue.js"
replicas = 2

[[jobs]]
name = "report"
schedule = "0 3 * * *"
command = "node report.js"

For these apps, skiff.toml decides, so the dashboard, the API and skiff worker or skiff job can't change them. Running a job now still works. A deploy without a [[workers]] section stops the app's workers.

Isolation

Every app runs in its own container. For code you don't fully trust, such as an agent's or a customer's, strong isolation runs it under gVisor, which gives it a kernel of its own in user space so it never talks to the server's kernel directly. Choose it under Isolation in the project's settings, or as isolation = "strong" under [deploy] in skiff.toml. A one-off run can ask for it too, with "isolation": "strong". Strong isolation is slower at heavy disk and network work, and some software that relies on unusual kernel features won't run under it.

It needs gVisor on the server. Installing it restarts Docker, and every app with it, so pick a quiet moment:

on your server
curl -fsSL https://gvisor.dev/archive.key | gpg --dearmor -o /usr/share/keyrings/gvisor-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/gvisor-archive-keyring.gpg] https://storage.googleapis.com/gvisor/releases release main" > /etc/apt/sources.list.d/gvisor.list
apt-get update && apt-get install -y runsc
runsc install && systemctl restart docker

Outbound network

By default an app can connect anywhere, like any server. Under Outbound network in the project's settings, a team owner can limit it to the team's own services (its apps and databases, and nothing on the internet), or to those and hosts you list, like api.openai.com or a range such as 203.0.113.0/24. It covers the app's workers, jobs and one-off runs too, and applies on the next deploy. In skiff.toml, set egress = "private", or egress = "list" with egress_allow = ["api.openai.com"], under [deploy].

  • Listed host names are looked up every five minutes. A service whose addresses change often, like some CDNs, is better listed as a range.
  • It needs Linux, with Skiff running as root as the installer sets it up, since it writes the server's firewall rules. Elsewhere, the setting says it isn't available.
  • On a network with a limited app, a new container is held back from the internet for a moment after it starts, until the rules know it, so a limited app is never briefly open.

What a limited app can still reach:

  • Every private address: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. That covers the team's apps and databases, and also anything else on the server's private network, like other machines in the same cloud network.
  • The server itself: the limits cover traffic leaving the server, not traffic to it. A limited app can reach any port the server listens on. Skiff's AI gateway, which an app with AI access calls its models through, is one. Keep other services on the server behind a password or bound to 127.0.0.1.
  • Name lookups: Docker answers them from the server, so a limited app can still look up names on the internet, though it can't connect to what they point at.
  • IPv6: the limits cover IPv4, which is what Docker's networks use unless IPv6 is turned on for them.

For code you don't trust at all, use a sandbox without internet, which has no network.

Machine permissions

Every app, worker and job starts with a few safer defaults: programs inside can't gain privileges the way sudo does, and the rarely used NET_RAW, MKNOD and AUDIT_WRITE capabilities are dropped. Some software needs more of the server than that: a VPN needs the NET_ADMIN capability and /dev/net/tun, a database may want IPC_LOCK, and a few tools need privileged mode. Each is off until the server's admin, an owner of the team that set Skiff up, grants it under Machine permissions in the project's settings. The change applies on the next deploy and is recorded in Activity.

  • Capabilities, like NET_ADMIN or SYS_PTRACE. Ones such as SYS_ADMIN reach past the container, and the dashboard warns before granting them.
  • Devices under /dev, like /dev/net/tun or /dev/fuse. A device is the server's own hardware, so the dashboard warns before granting one. The server's memory and disks, like /dev/mem or /dev/sda, can't be granted; use a volume.
  • Sysctls that stay inside the app: net.*, kernel.shm*, kernel.msg*, kernel.sem and fs.mqueue.*.
  • Setuid programs, for images that rely on sudo or similar at run time.
  • Capabilities Skiff drops, like NET_RAW for ping, come back when granted.
  • Privileged mode, the escape hatch for software like Docker-in-Docker. It gives the app near-full control of the server, so only grant it to software you trust.
  • The server's own network, for software that needs to see it, like some VPNs and discovery tools. The app runs one copy and listens on the server's port directly, and a deploy stops the old version before starting the new one, so there's a short gap.

A Compose file that asks for any of these shows what it asked for, with a button to fill it in. An app deployed with skiff deploy lists them in skiff.toml under [deploy] as cap_add, devices, sysctls, privileged, host_network and new_privileges.

Scheduled jobs

A job runs a command from your app's build in a one-off container with the app's environment and limits. It runs on a cron schedule, when its webhook is called, for each new file in a bucket, or any mix of those.

  • Every run is kept: what started it, how it ended, its exit code, how long it took and the end of its output. The last 50 runs are under the job's history on Jobs & workers, and in skiff job runs.
  • A timeout per job, 30 minutes unless you set one, up to a week. A run past it is stopped.
  • Retries: a failed run can be tried again up to 10 times, after 30 seconds, then a minute, then two, up to ten minutes apart. Running a job by hand tries once.
  • No overlap: if a run is still going when the next one is due, the next is skipped, and the history says so.
  • When Skiff restarts, such as for an upgrade, a run still going keeps going, and Skiff picks it back up: its history gets the whole output and how it ended. A run whose container stopped too, or a job with steps, is marked failed and tried again if it has retries left.
  • After downtime, a job that missed its time runs once when Skiff is back, unless you set it to skip missed runs.
  • Alerts: your alert channels hear when a job starts failing, after its retries, and when it works again.

Webhooks

A job with a webhook gets an address and a secret, shown on its row. Send a POST with:

  • the current Unix time in X-Skiff-Timestamp;
  • HMAC-SHA256 of <time>.<body> with the secret, as X-Skiff-Signature: sha256=<hex>.

A request is taken once, and only within five minutes of its time, so a copy of it can't start the job again. Sending the same one twice answers 200 without a second run. A request that couldn't be queued, because the job's queue is full, isn't counted, so you can send it again. Two requests with the same body in the same second have the same signature and count as one, so add a unique field, like an id or the time, to the body if you send repeats.

GitHub's X-Hub-Signature-256 header works too, so a GitHub webhook with the same secret can start the job, and its ping doesn't. Each GitHub delivery is taken once, by the delivery ID GitHub sends in X-GitHub-Delivery. GitHub's signature covers only the body, not that ID, so someone who captured a signed delivery could replay it with a new ID. Protection against replays holds fully only for requests signed the Skiff way.

The run gets the body, up to 64 KB, in SKIFF_WEBHOOK_BODY.

shell
body='{"ref":"main"}'
ts=$(date +%s)
sig=$(printf '%s.%s' "$ts" "$body" | openssl dgst -sha256 -hmac "$SECRET" | cut -d' ' -f2)
curl -X POST "$WEBHOOK" -H "X-Skiff-Timestamp: $ts" -H "X-Skiff-Signature: sha256=$sig" -d "$body"

New files in a bucket

A job can watch one of your team's buckets, or a folder in it. Each new file starts a run with the bucket in SKIFF_BUCKET and the file's key in SKIFF_OBJECT_KEY. A file written again starts another run.

  • Files already there when the job is added are left alone.
  • Skiff looks every 30 seconds, at up to 50,000 files under the folder, and starts up to 20 runs per look.
  • A large upload that finishes after newer files is still picked up, up to an hour later.
  • If the bucket can't be read, or the folder holds more files than Skiff looks at, the team gets an alert.

Write a job's own output outside the folder it watches, or each file it writes starts another run.

Runs from webhooks and buckets wait their turn: a job runs one at a time, up to 50 can wait, and waiting runs survive a restart.

Steps

A job can be a pipeline instead of one command: choose Several steps instead when you add it, or list [[jobs.steps]] in skiff.toml. Each step has a name, a command, and the steps it comes after:

skiff.toml
[[jobs]]
name = "nightly"
schedule = "0 2 * * *"

[[jobs.steps]]
name = "extract"
command = "python extract.py"

[[jobs.steps]]
name = "transform"
command = "python transform.py"
after = ["extract"]

[[jobs.steps]]
name = "report"
command = "python report.py"
after = ["extract"]

[[jobs.steps]]
name = "load"
command = "python load.py"
after = ["transform"]

A step runs once every step it comes after has succeeded, and steps with nothing between them, like transform and report here, run side by side, up to four at a time. When a step fails, the steps after it are skipped and the others carry on; the run counts as failed. Each run's history shows every step's outcome, and its output is labelled by step.

Each step runs in its own container from the app's image, with SKIFF_STEP set to its name, so steps hand data to each other through a volume, a database or a bucket, not through files in their containers. The job's timeout covers the whole run, and a retry runs every step again. A job has steps or a command, not both, and up to 20 steps.

One-off runs

Run a command once in a fresh container from your app's latest build, with its environment and limits, for a migration, a backfill or a CI step:

shell
skiff run shop-api -- npm run migrate
skiff run shop-api --timeout 2h -- "python backfill.py && echo done"

The output prints as it comes, and skiff run exits with the command's exit code, so a CI step fails when the command does. Ctrl-C stops the run. Runs time out after 30 minutes unless you say otherwise, and a team can have 3 going at once. The same is in the API, and agents can use it through the MCP tool run_command.

From the terminal

After skiff login, the CLI manages the same things as the dashboard. Attached databases and buckets reach an app on its next deploy. An app gets one database per variable, so attaching a second Postgres database to it is refused until the first is detached.

shell
skiff db create orders --engine postgres
skiff db attach orders shop-api      # adds DATABASE_URL to shop-api
skiff bucket create media
skiff bucket attach media shop-api   # adds S3_ENDPOINT, S3_BUCKET and its keys
skiff worker set shop-api queue --command "node queue.js" --replicas 2
skiff job add shop-api report --schedule "0 3 * * *" --command "node report.js"
skiff job add shop-api sync --schedule "*/15 * * * *" --command "node sync.js" --timeout 10m --retries 2
skiff job run shop-api report        # runs it now and prints its output
skiff job runs shop-api report       # its recent runs

Commands that delete data, like skiff db rm and skiff bucket rm, need --yes. The same actions are in the API.

GPUs

On a server with NVIDIA GPUs, an app can have some: choose how many under Limits per replica in the project's settings, or set gpus = 1 under [resources] in skiff.toml. The Server page lists each GPU with how busy it is, its memory and temperature, and which app has it, and /api/v1/metrics reports the same.

  • The server needs NVIDIA's driver and its container toolkit, set up for Docker (nvidia-ctk runtime configure --runtime=docker, then restart Docker). Until then, the Server page and the setting say what's missing, and a deploy that asks for GPUs stops with the reason.
  • An app keeps its GPUs from one deploy to the next. A model usually takes most of a card's memory, so the old version stops first and the new one starts on the same cards: the app is unavailable while the new version loads, and the old one comes back if the new one fails. Its replicas, workers, jobs and one-off runs share the GPUs.
  • A deploy that needs more than are free stops before replacing anything, and says which apps have the rest. Previews don't get GPUs.
  • Keep downloaded models on a volume, mounted where the model server looks: /root/.ollama for Ollama, or /root/.cache/huggingface for vLLM and anything else using Hugging Face (or set HF_HOME to the volume's path). Other projects can share that volume instead of downloading the same model again.
  • A large model can take minutes to load. Raise the health check Timeout (seconds) in the project's settings, or health_timeout in skiff.toml, up to 1800, so the deploy waits for it before switching traffic.
  • A sleeping app keeps its GPUs. With Sleep when idle on, the app's containers stop after the idle time and free the GPU memory, but the cards stay reserved for the app, so no other deploy is given them and waking never puts two apps on one card.

Training and batch runs on a GPU

A long run, like training a model or embedding a large dataset, is a job with GPUs and a volume:

  1. Give the app a GPU (see GPUs) and a volume for checkpoints, such as /checkpoints.
  2. Have the script save a checkpoint there every so often, and start from the latest one if it finds any.
  3. Add a job with the command, a timeout long enough for the whole run (up to a week), a few retries and a webhook. Start the run by calling the webhook: the call returns straight away, and the run gets its retries. Run now tries once and waits for the end, so keep it for short runs.

If the run crashes, runs out of memory or the server restarts, the retry starts from the last checkpoint instead of from the beginning. Its jobs, workers and one-off runs share the app's GPUs, so give a long run an app of its own if the app also serves traffic on them.

On a small server

  • Before each deploy, Skiff compares the app's memory limit, times its copies, with what the server has free, and the deploy log warns when it may not fit. With less than 1 GB of disk free, the deploy stops before building, since the build would fail partway.
  • When memory runs out, the kernel stops something. Skiff decides the order: previews first, then jobs and one-off runs, then your production apps. Managed databases, the router and the dashboard go last.
  • No app can take all the memory. One with no limit of its own is capped at 75% of the server.
  • The disk is watched. The team that set up the server hears when it passes 80% full and again at 90%, with how long the space should last at the past week's rate. Skiff clears unused images and old build cache every day, and all build cache once the disk is 90% full.
  • Each volume can have a budget. Click a volume's size under Volumes in the project's settings to set one, and the team hears when it grows past it.
  • Postgres fits the server. Postgres's own defaults assume a tiny machine. A Postgres database Skiff creates gets its memory settings sized to what its container may use: a quarter for shared_buffers, with work_mem, maintenance_work_mem, effective_cache_size and its shared memory sized to match. A database created before this gets them the next time Skiff starts its container, such as when you make it public or move it to another disk. Databases adopted from outside Skiff keep their own settings.

What Skiff doesn't do yet

  • UDP port ranges. A public UDP port is one port. Software that needs a range, like some WebRTC servers, doesn't fit yet.
  • More than one server. Replicas and autoscaling work within your server. There's no failover if it goes down, and database replicas run beside the database they copy.

On this page