Skip to Content
Docs

Run an agent

A long-running agent with no public address: its state survives restarts, it calls models within a budget, and work reaches it through an inbox.

Skiff doesn't give you an agent framework. Bring your own, in any language, and Skiff runs it the way an agent needs: always on, with nothing exposed to the internet, restarted when it crashes, and stoppable in one click.

Create one

In New project, choose your repository, image or Git URL and turn on Run as an agent. Skiff then:

  • Gives it no public address and doesn't wait for a port, so it can be a plain loop.
  • Mounts a volume at /data. Whatever the agent writes there survives deploys, crashes and server restarts.
  • Gives it AI access with a budget of 1,000,000 tokens a month, which you can change on the project's Settings tab. See AI gateway.
  • Opens an inbox for its work.

The container restarts when it exits, and Skiff alerts you if it keeps crashing.

The inbox

Work reaches the agent as events in its inbox, so it never needs an open port. The project's Overview shows where events come from and the last few that arrived.

  • Webhook: a signed POST to the address shown becomes one event, with the request body. Send the Unix time in X-Skiff-Timestamp, and HMAC-SHA256 of <time>.<body> with the secret as X-Skiff-Signature: sha256=…, as for job webhooks. Each request is taken once, within five minutes of its time. Two requests with the same body in the same second count as one, so add a unique field, like an id or the time, to the body if you send repeats.
  • GitHub: add a webhook in your repository's settings with the same address and secret. Each GitHub event arrives with its type, like issues or pull_request. GitHub's signature covers only the body, so each delivery is taken once by the ID GitHub sends, which isn't signed; replay protection holds fully only for Skiff-signed requests.
  • Schedule: a cron schedule like */15 * * * * adds an event each time it comes round. If Skiff was down through several, the agent gets one event, not a burst.
  • Email: on the Email page, forward an address to agent:<project> (like support@example.com → agent:helpdesk). Each message arrives as an email event whose body is JSON with from, to, subject, date, messageId and text: the plain-text part, or the HTML when there's none, up to 40 KB. Attachments aren't included. See email forwarding for setting up the domain.

The agent asks for its next event and says when it has finished:

agent.py
import os, requests

base = os.environ["SKIFF_AI_URL"] + "/_skiff"
auth = {"Authorization": "Bearer " + os.environ["SKIFF_AI_TOKEN"]}

while True:
    r = requests.get(base + "/events?wait=60", headers=auth, timeout=90)
    if r.status_code != 200:
        continue  # 204: nothing arrived within the wait
    event = r.json()  # id, source, kind, body, created, deliveries
    handle(event)
    requests.post(f"{base}/events/{event['id']}/done", headers=auth)

wait holds the request open for up to 60 seconds until an event arrives. An event the agent takes but doesn't finish within five minutes, because it crashed or hung, goes back in the inbox, and deliveries says how many times it has been handed out. After five deliveries, or a week without being finished, Skiff gives up on an event: it stops going out and shows as "gave up" in the inbox. Finished and given-up events are kept for a week. The inbox holds up to 1,000 unfinished events; past that, webhooks are refused with 429.

Sandboxes

When an agent writes code, it can run it somewhere other than its own container. It sends the code and any files to Skiff, which runs them in a new container and removes it afterwards:

agent.py
r = requests.post(base + "/sandboxes", headers=auth, timeout=960, json={
    "command": "python main.py",
    "files": {"main.py": code, "data/input.csv": csv_text},
    # optional: "image": "node:22-alpine", "internet": True, "timeout": 300,
    # and "binaryFiles": {"photo.jpg": "<base64>"}
})
result = r.json()
# exitCode, output, and files: everything left in the working directory, base64-encoded

A sandbox:

  • Starts from python:3.12-alpine unless you name another image.
  • Has no network at all unless the request sets "internet": true. Even then it never joins your apps' network, so it can't reach your databases or other sandboxes.
  • Keeps to the agent's outbound limits. An agent kept to the team's own services can't have sandboxes with the internet, and one limited to a list of hosts gets sandboxes that reach only those hosts.
  • Runs with no Linux capabilities, 512 MB of memory, one CPU and at most 256 processes, and under gVisor when the server has it installed, so the code talks to gVisor's kernel rather than the server's.
  • Stops after two minutes, or the timeout you give in seconds, up to fifteen.
  • Hands back up to 16 MB of files, 8 MB each; skipped lists any left out. Output is cut at 256 KB.
  • Is stopped if it writes more than 2 GB, in its working directory or anywhere else.

A browser

For an agent that has to use a website, set "browser": true. The sandbox then starts from Microsoft's Playwright image, with Python, Playwright and Chromium ready, 2 GB of memory and the internet on:

agent.py
script = """
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    page = p.chromium.launch().new_page()
    page.goto("https://news.ycombinator.com")
    print(page.title())
    page.screenshot(path="front.png")
"""
r = requests.post(base + "/sandboxes", headers=auth, timeout=960,
                  json={"browser": True, "command": "python run.py", "files": {"run.py": script}}).json()
png = base64.b64decode(r["files"]["front.png"])

The first browser sandbox on a server prepares its image from Microsoft's, about 2 GB, which can take a few minutes; that wait doesn't count against the sandbox's timeout.

An agent runs up to three sandboxes at once. The project's Overview lists the last few with their output, and Stop agent ends any that are running.

Approvals

Before something it can't undo, an agent can ask a person first. The request goes to your team's alerts, and appears at the top of the agent's page with Approve and Deny and room for a note back:

agent.py
r = requests.post(base + "/approvals?wait=60", headers=auth, json={
    "action": "delete 412 inactive accounts",   # up to 200 characters
    "detail": "Not signed in since March. Backup taken at 03:40.",
}).json()
while r["status"] == "pending":
    r = requests.get(f"{base}/approvals/{r['id']}?wait=60", headers=auth).json()
if r["status"] == "approved":
    delete_accounts()
# r["note"] holds anything the person wrote back

A request nobody answers within a day comes back expired; stopping the agent denies any still waiting. An agent can have 20 requests waiting at once. Skiff only records the answer: the agent is the one that has to wait for it.

Runs

The agent panel lists the agent's runs, and each opens to its steps laid out in time, with the model, tokens and any error on each.

Every model call through Skiff is recorded, so a run shows up even if the agent does nothing. For the agent's own steps (planning, tool calls, retries), use OpenTelemetry, which most agent frameworks support. Skiff sets the standard variables for an agent, so its exporter sends to Skiff with no setup:

  • OTEL_EXPORTER_OTLP_TRACES_ENDPOINT and OTEL_EXPORTER_OTLP_TRACES_HEADERS: Skiff's address and the agent's token.
  • OTEL_EXPORTER_OTLP_TRACES_PROTOCOL: http/protobuf. Skiff also takes OTLP's JSON encoding.
  • OTEL_SERVICE_NAME: the project's name.

A model call made inside a traced step carries its trace context, and Skiff files the call under that step. Spans named with OpenTelemetry's GenAI conventions (gen_ai.request.model, gen_ai.usage.input_tokens, gen_ai.tool.name and so on) show their model, tokens and tool. Runs are kept for a week, up to 20,000 steps per agent.

To see what a run cost, add your models' prices under Settings → Integrations → Model prices, in dollars per million tokens, from your provider's pricing page. Skiff doesn't keep a price list, since providers change theirs often. A name also covers its dated versions, so gpt-4o-mini prices gpt-4o-mini-2024-07-18, but gpt-4 doesn't price gpt-4o. Add each model you use by name. A run that used a model without a price shows "at least" the cost of the ones with one.

Memory

For memory an agent searches by meaning, create a database on the Databases page and choose Postgres + pgvector (or skiff db create memory --engine pgvector). It's Postgres 16 with the pgvector extension already switched on, so vector columns and nearest-neighbour queries work straight away:

create table notes (id bigserial primary key, body text, embedding vector(1536));
create index on notes using hnsw (embedding vector_cosine_ops);
select body from notes order by embedding <=> $1 limit 5;

Underneath it's an ordinary Skiff Postgres database: daily backups, restore checks, point-in-time recovery and offsite copies work the same, and attaching it gives the agent DATABASE_URL.

Stop it

Stop agent on the project's Overview does everything at once: its containers, sandboxes and any commands it's running stop, and Skiff refuses its model calls and holds its inbox. Start brings it back with its events still waiting.

On this page