What Sarpius Functions is
A function is a Component of a Project, next to your containers, databases and buckets. It shares the Project routing and members. Instead of a container that runs all the time, every invocation gets a Firecracker microVM, and you are billed for the work that actually ran.
- Runtimes: Node.js 22, Python 3.12, PHP 7.4 to 8.5 (8.4 by default) and Ruby 3.3, 3.4 or 4.0 (3.4 by default). No other languages.
- Triggers: an HTTP request, or a cron schedule.
- Source: a git repository with a function.json at its root. A push to the configured branch builds a new version.
- Deploys: a failed build leaves the previous version live, and a new version takes over without downtime.
- Billing: GiB-seconds plus invocations, from your normal wallet, with a free monthly allowance and spending limits you set.
Note
Functions is available in beta and open to all accounts. Anyone with an account can create functions.
Create a function
- Open your Project in the console, choose Functions in the sidebar, then New function.
- Enter a name, the repository and the branch to build from (main when you leave it empty).
- Optionally enter a path on the Project domain, for example /hooks/checkout. The console adds it as a Project route that points at the function.
- Create the function. The function exists immediately, but nothing is live yet: the first build starts on your next push to the branch.
Any git provider that Sarpius Launch supports works: GitHub, GitLab, Gitea, Bitbucket or a generic remote. A function repository holds one function, with function.json at the repository root. A function cannot be created from a subdirectory of a monorepo.
Note
The first build starts on the next push, not when you press Create. If the repository already has the code you want, push an empty commit or any change to the configured branch.
function.json
The manifest sits at the repository root and tells the platform how to run the code. It travels with the code, so a change to memory or timeout is a commit like any other.
json
{
"lang": "node",
"tier": 128,
"entry": "index.mjs",
"timeout_s": 10
}
- lang (required): "node", "python", "php" or "ruby".
- tier (required): the memory in MiB. One of 128, 256 or 512, as a number.
- timeout_s (required): the maximum duration of one invocation, a whole number from 1 to 60.
- php (optional, PHP only): the PHP version as a string, for example "8.2". One of "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" or "8.5"; the default is "8.4". It is only allowed together with "lang": "php" and must be a string, not a number (write "8.0", not 8.0). See the PHP section.
- ruby (optional, Ruby only): the Ruby version as a string. One of "3.3", "3.4" or "4.0"; the default is "3.4". It is only allowed together with "lang": "ruby" and must be a string, not a number (write "4.0", not 4.0). Ruby runs on every memory tier. See the Ruby section.
- entry (optional): the file that holds the handler, in the repository root. The default is index.mjs for Node.js, main.py for Python, index.php for PHP and main.rb for Ruby. The name may use letters, digits, dot, underscore and dash (at most 128 characters), may not start with a dot and may not contain "..".
Heads up
A manifest that breaks any of these rules fails the build with guest_invalid_manifest, and so does an entry file that does not exist in the repository (guest_missing_entry). The previous version stays live.
Write the handler
Your entry file exports or defines a function called handler. It receives one request object and returns a response object. Node.js and Python accept an asynchronous handler; PHP and Ruby are synchronous.
Node.js loads the entry file as an ES module and takes the named export handler (a default export that carries a handler property also works). That is why the default file name ends in .mjs.
js
export async function handler(request) {
const input = request.body
? JSON.parse(request.body)
: {};
return {
status: 200,
headers: {
"content-type": "application/json"
},
body: JSON.stringify({
message: `Hello, ${input.name ?? "world"}`,
method: request.method,
path: request.path
})
};
}
Python loads the entry file as a module and calls its top-level function handler, which may be a plain function or an async def. The request is a dict.
python
import json
def handler(request):
data = json.loads(request["body"]) if request["body"] else {}
return {
"status": 200,
"headers": {"content-type": "application/json"},
"body": json.dumps({
"message": "Hello, " + data.get("name", "world"),
"method": request["method"],
"path": request["path"],
}),
}
PHP includes the entry file (index.php by default) and calls a function named handler that you define in the global namespace. Do not put a namespace declaration around it. The request is an array with the same fields as below, and the handler returns an array.
php
<?php
function handler(array $req): array
{
$data = $req['body'] !== '' ? json_decode($req['body'], true) : [];
return [
'status' => 200,
'headers' => ['content-type' => 'application/json'],
'body' => json_encode([
'message' => 'Hello, ' . ($data['name'] ?? 'world'),
'method' => $req['method'],
'path' => $req['path'],
]),
];
}
The request object has these fields:
- method: the HTTP method, for example "POST". For a cron run it is always "POST".
- path: the path the function was called on, without the query string. For a function reached on a Project route, this is the full path including the route prefix, because the prefix is not stripped.
- query: the raw query string without the leading "?", or an empty string.
- headers: an object of header names to string values. Several values of one header are joined with ", ". Do not rely on the case of the names; compare them case-insensitively.
- body: the request body decoded as UTF-8, or an empty string. Bytes that are not valid UTF-8 are replaced, so a binary body does not survive in this field. In PHP, body is different: it holds the exact raw bytes of the request body (decoded from base64, no UTF-8 replacement), so binary payloads arrive intact.
- body_b64: the exact request body as base64, for binary payloads.
The headers the function receives are filtered. The platform removes hop-by-hop headers and anything starting with x-functions- or x-sarpius-. It also replaces x-forwarded-for, x-real-ip, x-forwarded-host and x-forwarded-proto with values it determined itself, so a visitor cannot choose the client address or host your function sees.
The response object has these fields:
- status: a whole number from 200 to 599. Default 200.
- headers: an object whose values are all strings. At most 64 headers, each value at most 8 KiB and without line breaks. content-length, transfer-encoding, connection and similar headers are dropped, along with anything starting with x-functions- or x-sarpius-.
- body: a string or bytes (a Buffer in Node.js, bytes or bytearray in Python). Anything else is converted with a plain string conversion, so return JSON.stringify(...) or json.dumps(...) instead of an object. In PHP the body must be a string, a scalar (int, float, bool) or an object with __toString(); an array or other object body is rejected as a bad response, so return json_encode(...). Maximum 6 MiB.
Heads up
A handler that throws, or returns something that is not an object (a dict in Python, an array in PHP, a Hash in Ruby), counts as a failed invocation and the caller gets a platform error page, not your error text. Return a status of 500 yourself if you want to send your own error body. A Set-Cookie header keeps working, but a Domain attribute is dropped unless it names exactly the request host.
Builds and versions
Every push to the configured branch builds a new immutable version of the function, in a disposable microVM with a 10 minute limit. When the build succeeds the new version becomes active. The switch changes which version answers new requests; there is no downtime, and the previous version keeps answering until the moment the new one is active.
- A failed build never activates. The last good version stays live, and the Builds tab shows the failed build, its error code and its log.
- Node.js dependencies: if package.json exists, a package-lock.json (or npm-shrinkwrap.json) must exist too. The build runs npm ci, and then npm run build when package.json defines a build script. A .npmrc file is rejected.
- Python dependencies: put them in requirements.txt with hashes. The build installs with pip --require-hashes. pyproject.toml, Pipfile and setup.py are rejected.
- Ruby dependencies: a Gemfile needs a committed Gemfile.lock; the build runs bundle install frozen, with gems that have no prebuilt package compiled in the build environment. See the Ruby section.
- During the build only a fixed list of hosts is reachable, the same for every language: registry.npmjs.org, pypi.org, files.pythonhosted.org (any path), repo.packagist.org (only /packages.json and the /p2/<vendor>/<package>.json metadata), rubygems.org (only /gems/<name>.gem downloads), index.rubygems.org (only the compact index: /versions, /names and /info/<gem>) and api.github.com (only /repos/<owner>/<repo>/zipball/<40-hex commit>, which the platform fetches from codeload.github.com on your behalf). Nothing else, so a build cannot download from other hosts.
- Size limits: the packaged version is at most 50 MiB compressed, 48 MiB expanded and 10,000 files.
PHP dependencies have their own rules, described in the next section, and Ruby dependencies are described in the Ruby section. The error codes you can see on a failed build are guest_invalid_manifest, guest_missing_entry, guest_invalid_dependencies, guest_build_failed (a dependency or build command failed), guest_build_timeout, guest_source_limit, guest_output_limit, guest_native_dependency_missing, guest_native_rpath_rejected and guest_native_binary_unsupported (a compiled Ruby gem needs a library the runtime does not have, an unsafe library search path, or a binary the runtime cannot load) and guest_unsafe_output (the build left a link or special file where only files may be). The build log shows the command output that explains guest_build_failed.
PHP
PHP functions run PHP 8.4 unless function.json names another version (see the PHP versions paragraph below). The handler is a global function handler(array $req) in the entry file, index.php by default, with no namespace. The response is an array with status, headers and body, as described above.
- Warm instances: globals and static variables survive between calls in a warm instance, so a connection or a cache you keep in a static is reused. Do not rely on it, because a new instance starts empty.
- Fatal errors: a fatal error such as exit() or running out of memory ends that instance. The caller gets a platform error page and the next call starts a fresh instance.
- Memory: memory_limit follows the tier you choose in function.json. It is the memory of the microVM minus 48 MiB for the runtime itself, so slightly below the tier, with a floor of 32M.
- Extensions: ctype, curl, dom, fileinfo, iconv, intl, mbstring, openssl, pdo, pdo_pgsql, pdo_mysql, pdo_sqlite, phar, simplexml, sodium, tokenizer, xml, zip and json. The set is the same on every PHP version. There is no opcache.
- Release size: a release is at most 48 MiB expanded. Libraries and SDKs fit; a full framework such as Laravel does not.
PHP versions: set the version in function.json with the php key. Without it your function runs PHP 8.4, exactly as before. The build and the running function use the same version, so composer install and composer check-platform-reqs check your lock file against the PHP you chose.
json
{
"lang": "php",
"php": "8.2",
"tier": 128,
"timeout_s": 10
}
- PHP 7.4: Alpine 3.15, PHP security support ended 2022-11-28, Alpine package updates ended 2022-05-23.
- PHP 8.0: Alpine 3.16, PHP security support ended 2023-11-26, Alpine package updates ended 2022-11-22.
- PHP 8.1: Alpine 3.19, PHP security support ended 2025-12-31, Alpine package updates ended 2024-05-22.
- PHP 8.2: Alpine 3.22, PHP security support until 2026-12-31, Alpine package updates ended 2025-12-03.
- PHP 8.3: Alpine 3.24, PHP security support until 2027-12-31, Alpine end date not yet known.
- PHP 8.4 (default): Alpine 3.24, PHP security support until 2028-12-31, Alpine end date not yet known.
- PHP 8.5: Alpine 3.24, PHP security support until 2029-12-31, Alpine end date not yet known.
End of life: the Alpine date is the end of the Alpine community repository that supplies the PHP packages. When the PHP date or the Alpine date has passed, the build still succeeds, but its log starts with a warning and the function list shows an EOL badge next to the version. If PHP itself is past its date the warning reads, for PHP 7.4:
text
WARNING: PHP 7.4 is end of life since 2022-11-28 and receives no security updates. Its base system (Alpine 3.15) receives no package updates since 2022-05-23. Upgrade recommended.
If only the base system is past its date, for example PHP 8.2 on Alpine 3.22:
text
WARNING: PHP 8.2 runs on Alpine 3.22, which receives no package updates since 2025-12-03. Upgrade recommended.
Heads up
A php key without "lang": "php" fails the build with php_version_without_php. A value that is not one of the seven versions above (including a number instead of a string) fails it with php_version_unsupported. Both keep the previous version live. A composer.lock that requires a newer PHP than the version you chose fails in composer check-platform-reqs with the Composer message.
Dependencies come from Composer. If composer.json exists, composer.lock must exist too, and the build installs exactly what the lock file names.
- Only packages from Packagist whose download is a GitHub zipball pinned to a commit are accepted. Every package in the packages list of composer.lock must use such a dist: type zip, a URL of the form https://api.github.com/repos/<owner>/<repo>/zipball/<commit> and a dist.reference equal to that commit. Development dependencies (packages-dev) are not installed: the build runs composer install --no-dev.
- A composer.json with a repositories section is rejected, and so is an auth.json. There are no dist or source mirrors and no credentials.
- Composer scripts run. Composer plugins only run when your composer.json allows them in config.allow-plugins; the platform never allows a plugin for you. A plugin that is not allowed is skipped (the build log shows the Composer warning) and the build continues without it.
- The build can reach only the shared list of hosts described under Builds and versions. Composer itself needs just the Packagist metadata and the GitHub zipballs.
Note
Integrity: GitHub downloads are pinned by commit. Composer does not verify a content hash for them, so the commit in composer.lock is the guarantee, not a checksum. The pin covers the Composer packages in composer.lock only. Composer scripts and allowed plugins are your own code and run during the build with network access to the build registries, so anything they fetch, and anything you commit under vendor/, ends up in the release unpinned.
These build error codes are specific to PHP and are shown as they are in the build list:
- php_version_without_php: function.json has a php key but "lang" is not "php".
- php_version_unsupported: the php value is not one of "7.4", "8.0", "8.1", "8.2", "8.3", "8.4" or "8.5", or is not a string.
- composer_auth_json: the repository contains an auth.json, which is not allowed.
- composer_repositories: composer.json declares repositories, which is not allowed.
- composer_json_invalid: composer.json is not a regular file (a symlink is refused), is larger than 1 MiB, or is not a JSON object.
- composer_lock_missing: composer.json exists but composer.lock does not.
- composer_lock_invalid: composer.lock is not a regular file (a symlink is refused), is larger than 16 MiB, is not a JSON object, or has no packages array.
- composer_dist_unsupported: a package in composer.lock has a dist that is not a zip from a GitHub zipball URL of the accepted form, or lists dist or source mirrors.
- composer_source_only: a package in composer.lock only has a source checkout and no download.
- composer_reference_mismatch: the commit in a package download URL differs from the reference recorded for that package.
- composer_shasum_unsupported: a package carries a content hash, which this build does not support for GitHub downloads.
- guest_invalid_dependencies: the dependency check inside the build environment rejected the project (for PHP: an auth.json, a repositories key, a missing composer.lock, or a lock that breaks the dist rules). It is normally caught earlier by one of the specific codes above. Node.js and Python have their own dependency rules that produce the same code.
- guest_build_failed: composer install or composer check-platform-reqs exited with an error, for example a missing PHP extension or a version constraint that cannot be met. The build log shows the Composer output.
Ruby
Ruby functions run Ruby 3.4 unless function.json names another version: "ruby": "3.3", "3.4" or "4.0", as a string, only together with "lang": "ruby". The handler is a global method handler(req) in the entry file, main.rb by default. The request is a Hash with string keys (method, path, query, headers and body), the same fields as above; body is a String, UTF-8 when the bytes are valid UTF-8 and binary otherwise.
ruby
require 'json'
def handler(req)
data = req['body'].empty? ? {} : JSON.parse(req['body'])
{
status: 200,
headers: { 'content-type' => 'application/json' },
body: JSON.generate(
message: "Hello, #{data.fetch('name', 'world')}",
method: req['method'],
path: req['path']
)
}
end
- The response is a Hash with status (an Integer from 100 to 599; default 200), headers (a Hash; default empty) and body. Symbol and string keys both work; when both exist the symbol wins, so an explicit nil body is an empty body.
- body: a String, or a scalar that is converted with to_s. A Hash or an Array as body is a bad response, so return JSON.generate(...). Anything that cannot be converted or encoded, a response over 8 MiB, or a header that is not valid UTF-8 is also a bad response; the instance keeps running.
- Errors: an exception that inherits from StandardError raised in your handler is a failed invocation and the instance stays healthy. exit, abort, exit! and running out of memory end the instance: the caller gets a platform error page and the next call starts a fresh instance.
- Warm instances: globals, constants and class state survive between calls in a warm instance. Do not rely on it, because a new instance starts empty.
- Memory: Ruby runs on all three tiers (128, 256 and 512 MiB). On 128 MiB a function that has loaded a native gem has roughly 60 MiB of memory left (measured), so choose 256 MiB or more for heavier work.
- Support: Ruby 3.3 until 2027-03-31, Ruby 3.4 until 2028-03-31 and Ruby 4.0 until 2029-03-31. After that date, or when the base system under the version no longer receives updates, the function list shows an EOL badge and the build log starts with a warning.
Gems: put a Gemfile and a committed Gemfile.lock next to function.json. The build runs bundle install frozen, in the build environment, and ships the installed gems with your code; your Gemfile is then loaded with bundler/setup before your entry file.
- Only rubygems.org is a gem source. A GIT, PATH or PLUGIN section in Gemfile.lock, or a remote other than https://rubygems.org/, fails the build with gem_source_not_allowed.
- The lockfile must list a platform the runtime can use: x86_64-linux-musl or ruby. Add it with: bundle lock --add-platform x86_64-linux-musl. Without it the build stops with gem_lock_platform_missing.
- A Gemfile without a Gemfile.lock is gemfile_lock_missing; a lockfile that is malformed in any other way is gemfile_lock_invalid. A .bundle/config in the repository is bundle_config_not_allowed. A "ruby" value in function.json other than "3.3", "3.4" or "4.0" is ruby_version_unsupported, and a "ruby" key together with another "lang" is ruby_version_without_ruby.
- The build always uses the Bundler of the Ruby image; the BUNDLED WITH line is not used to download another Bundler.
- Native gems are supported. Gems that ship a prebuilt package for the musl platform (pg and nokogiri are tested) are installed as that package and bring their own libraries; gems without one (bcrypt is tested) are compiled during the build against the system libraries of the build environment: libpq, libxml2 and libxslt, yaml, libffi, openssl, zlib and gmp, and the C++ runtime. A compiled gem that needs any other library fails the build with guest_native_dependency_missing and the log names the library, instead of failing at the first call.
- The compiler flags are -O2 -march=x86-64-v2. A gem that sets -march=native itself is outside what the platform can enforce, and may crash on a host with a different processor.
HTTP trigger
A function is reachable in two ways, and a function can have both:
- A subdomain on sarpius.app. The Project's primary component gets its own address, and every path on it goes to the function.
- A path on the Project domain, such as /api/hello, added as a Project route when you create the function or later under Routing. This is how a function that is not the primary component is reached.
Any method, path, query, set of headers and body up to 6 MiB reaches the handler as described above. A larger request body is refused with 413 before any code runs.
What the caller sees depends on who answered:
- Your handler returned a response: the caller gets exactly that status, those headers and that body, including 4xx and 5xx statuses you chose.
- The handler threw, returned an invalid response, or the function could not be loaded: a platform error page (502).
- The invocation ran longer than timeout_s: a platform error page (504), and the microVM is destroyed.
- No active version yet (the first build has not finished, or every build so far failed): 404.
- The platform cannot prove it is ready to bill and isolate the invocation, or has no capacity right now: a platform error page (503). Your code does not run.
- A spending limit is reached, or your wallet cannot cover more usage: HTTP 402, before any microVM is started.
Between invocations a microVM may be paused and reused for the same function version, one request at a time, so a warm request is much faster than a cold one. Do not keep state in memory and rely on it: a warm instance is an optimisation, never a guarantee, and a timed-out instance is thrown away.
Cron trigger
A schedule runs the active version of the function on a timer. Add schedules on the Schedules tab of the function.
- Expression: a standard five-field Unix cron expression (minute, hour, day of month, month, day of week). The tab previews the next five runs before you save.
- Timezone: an IANA timezone such as Europe/Amsterdam. The default is UTC.
- Limits: at most 10 schedules per function and 50 per account. Per account, at most 2 cron runs execute at the same time.
- What the function receives: a POST to the path / with a JSON body that holds "trigger": "cron", the "schedule_id" and the "scheduled_for" time. A cron run is billed like a request.
Heads up
Cron is at most once. A slot is recorded before it runs and is never run again, even after a crash, because the function may already have had side effects. Slots that were missed, for example during an outage, are not caught up later. Write functions that are safe to skip.
Each run appears in the runs list of the schedule (the last 50, kept for 30 days) with one of these statuses:
- ok: the handler returned a response.
- handler_error, timeout and failed: the handler threw, exceeded timeout_s, or the invocation failed on the platform side. Ten of these in a row disable the schedule; turn it back on after you have fixed the function.
- abandoned: the run was claimed but never finished, for example after a restart. It is not retried.
- skipped_budget: a spending limit is reached or the wallet is empty. The run is not executed.
- skipped_capacity: the cron share of the capacity, or your account limit of 2 simultaneous runs, was in use.
- skipped_overlap: the previous run of the same schedule was still running.
- skipped_no_version: the function has no active version yet.
- skipped_disabled: the schedule was switched off before the run started.
Limits and what is not available
- Memory: 128, 256 or 512 MiB per invocation, chosen in function.json.
- Duration: at most 60 seconds per invocation. A shorter timeout_s is enforced exactly.
- Request and response bodies: at most 6 MiB each.
- Code: the packaged version must fit in a 64 MiB code disk, within the build size limits above.
- Network: a function can reach the public internet. It cannot reach private network ranges or Sarpius platform addresses, cannot send mail over ports 25, 465 or 587, and outside DNS cannot use UDP. Sarpius domains are reached like any visitor reaches them.
- Files: the code is read-only. Do not expect anything you write to disk to be there on the next invocation.
Heads up
Environment variables are not available yet. The console shows an Environment tab for a function, but its values are not passed to your code today, so do not put configuration or secrets there and expect the handler to read them. A database connection for functions is not available yet either, and no database credentials are injected.
Pricing and the free allowance
Usage is billed from your normal Sarpius wallet. There are two meters, and there is no minimum charge.
- Compute: EUR 0.000016 per GiB-second. GiB-seconds are the memory tier in GiB times the duration of the invocation in seconds. The duration is rounded up to whole milliseconds, and the memory is the tier from function.json, not the memory the code happened to touch.
- Invocations: EUR 0.20 per million invocations.
Every month the first 100,000 GiB-seconds and the first 1,000,000 invocations are free. The allowance is applied first. Amounts are billed in whole cents, rounded down, and the remainder stays in your usage until it adds up to a cent.
Example: a function with 128 MiB, 500 ms on average and 5,000,000 invocations in a month.
- Compute: 128/1024 x 0.5 x 5,000,000 = 312,500 GiB-seconds. Minus 100,000 free leaves 212,500, times EUR 0.000016 = EUR 3.40.
- Invocations: (5,000,000 - 1,000,000) / 1,000,000 x EUR 0.20 = EUR 0.80.
- Total: EUR 4.20.
An invocation that is refused before a microVM starts (for example with 402) is not billed.
Spending limits
On the Spending limit tab you can set a monthly limit in EUR for one function and a separate monthly limit for all functions in the Project. Leave a field empty for no limit. A value of 0 is allowed and stops the function from running at all. Amounts have at most two decimals.
- When a limit is reached, new HTTP requests get HTTP 402 and a clear "spending limit reached" page, and cron runs are skipped as skipped_budget. Invocations that already started finish.
- The same happens when your wallet cannot cover further usage: the function is blocked with 402 until the wallet is funded.
- The limit is checked against gross usage before the free allowance is subtracted, so it can stop a function earlier than the final bill would. It is a hard stop, not a reservation: an invocation that was already running when the limit was reached can still add its cost.
Builds, invocations and cost in the console
Each function has its own page in the Project with these tabs:
- Overview: requests and errors in the last 24 hours, the median (p50) and p95 duration, cost this month, requests per hour, and the live version.
- Builds: the last builds with status, duration and commit, the full build log, and a notice when a failed build leaves an older commit live.
- Invocations: the last 100 requests and cron runs with time, trigger, method and path, status, duration and billed amount, and the 402 spending-limit result.
- Schedules: your cron schedules, their next runs and their recent runs.
- Spending limit: the function and Project limits and what has been used this month.
- Settings: the production branch, and deleting the function (type the name, and your 2FA code if your account has 2FA).
The Functions page of the Project lists every function with its status (Active, Building, Failed, Spending limit reached, Stopped), today's requests and the cost this month for all functions together.
Note
The build log is kept per build. The text your handler prints to stdout or stderr is not stored, so return what you need to know in the response, or call an external service you control.