Skip to content

Functions

A function is TypeScript (or JavaScript) that you deploy once in the console and call by name. Each call runs in a fresh Slice isolate, exactly like /v1/sandbox/eval, and counts as one run.

A function has exactly one export default: the function to call. It receives the JSON input of the call and a context, and returns any JSON value (or a promise of one).

// ctx: { function: string, version: number, requestId: string }
export default async function (input: { name?: string }, ctx: { function: string; version: number }) {
console.log("invoked", ctx.function, "v" + ctx.version);
return { greeting: `hello ${input?.name ?? "world"}` };
}

The source is limited to 64 KB. Everything that works in eval works here: TypeScript, node: modules that Slice supports, fetch to allowed hosts, Slice.kv and checkpoints within the run.

Create the function in Console, Functions, New function. A name starts with a lowercase letter and uses lowercase letters, digits, - and _ (at most 63 characters). Every deploy creates a new immutable version and makes it live. Under Versions, Roll back to this makes an older version live again in one step. Changes reach the API within about ten seconds.

Terminal window
curl https://api.slicevm.com/v1/functions/hello/invoke \
-H "Authorization: Bearer $SLICE_API_KEY" \
-H "content-type: application/json" \
-d '{"input": {"name": "Ada"}}'

The body is {"input": <any JSON>} (at most 256 KB; omit it for null). Files the function writes under /artifacts come back in artifacts, as for any sandbox run; add "artifacts": false to turn that off. The response is the eval result plus the version that ran:

{
"ok": true,
"stdout": ["invoked hello v3"],
"result": { "greeting": "hello Ada" },
"violation": null,
"telemetry": { "coldBootUs": 0.9, "vmExecUs": 412.5, "totalUs": 1830.2, "fuelConsumed": 18211, "peakMemoryKb": 64 },
"function": { "name": "hello", "version": 3 }
}

As with eval, a thrown error or rejected promise is ok: false with the message in result, and a limit hit is ok: false with a violation. Both are HTTP 200.

The key needs full access, Invoke any function (functions:invoke), or Invoke one function for this name (functions:invoke:hello). See API keys.

Status Code When
400 bad_request Malformed JSON
401 unauthorized Missing, unknown, revoked or expired key
403 forbidden The key may not call this function, the key is not a console key, or the account has no plan or is paused
404 not_found No function with that name on your account (counts as one run)
413 payload_too_large Input over 256 KB
429 rate_limited Your account (or this function) already has its maximum runs in flight
429 quota_exceeded Monthly runs used up
503 overloaded All workers busy; retry with backoff

The Sandbox SDK has no invoke method yet; call the endpoint with fetch or any HTTP client.

Every function with a live version is also a tool on the hosted MCP server. An AI agent connected with your key sees it in tools/list and can call it like any other tool:

Property Value
Tool name fn_<name>, with - replaced by _ (send-invoice becomes fn_send_invoice)
Input The input schema read from the type of your function’s first parameter (the tool’s arguments are the input), or { "input": <any JSON> } when the parameter has no type
Returns The function’s result, plus function: { name, version }
Description The function’s description, so write it for the model: what it does and what input it expects
Cost One run per call, like an HTTP invoke
Key Console key with full access, functions:invoke, or functions:invoke:<name>

A new function or a rollback shows up in MCP clients the next time they list tools, within about ten seconds of the change.

To give an agent exactly one function and nothing else, create a key with Invoke one function and use it in the agent’s MCP config. The agent then sees only that function’s tool.

Type the first parameter so the agent knows what to send: export default async function (input: { orderId: number; /** Why the customer asked */ reason?: string }) becomes a tool schema with a required orderId and an optional, described reason. Each version keeps its own schema; edit it on the function page under Input schema when the inferred one is not what you want.

For more control (choose which functions an agent sees, pin versions, rename tools, cap daily runs, or let the agent call several functions from one script), put the functions on an MCP server.

Under Settings each function has its own limits, within your plan:

  • Memory per run (KB): default and maximum is your plan’s cage.
  • Fuel per run: default and maximum is your plan’s cap. Steps, function calls and work inside built-ins (sort, string methods, regular expressions, JSON) count.
  • Time per run (ms): wall-clock limit; default and maximum is your plan’s (Free 10 s, Pro 30 s, Scale 60 s).
  • Runs in flight for this function: keeps one busy function from using all of your account’s slots.
  • Allowed hosts: network is off unless a host is listed. Cloud metadata addresses are always blocked.
  • Log inputs: keeps the first 4 KB of each run’s input in the run log (see Runs). Off by default; leave it off when inputs carry secrets or personal data.

The Test tab runs the live version with any input and shows the result, stdout, fuel and memory against the limits, and the files the run wrote. Write the input as Raw JSON (with formatting and validation), or switch to Structured to fill in fields built from the function’s input schema (experimental). Fill from schema starts from an input with every field; Copy as curl copies the same call for a terminal. The last input is remembered in your browser. Test runs count toward your monthly runs.

The Runs tab lists every run of the function from the last 30 days, newest first: HTTP invokes, Test runs, MCP tool calls and calls from code-mode scripts. Each row shows the outcome, version, where it came from, duration, memory and the key; open one for the run id, VM time, fuel, the error and the files it kept, each linking to Artifacts. Filter by outcome or source. Runs show up within a minute. Your code can read the same log with GET /v1/functions/{name}/runs and a key with the Read run logs and artifacts access.

The log stores no results and no stdout. Inputs are stored only when Log inputs is on; then a run’s input is shown with Run again in Test.

Free Pro Scale
Functions 3 50 500
Source size 64 KB 64 KB 64 KB
Input size 256 KB 256 KB 256 KB

Runs, memory, fuel and runs in flight follow your plan: Plans and limits.