Functions

Run your own Python or JavaScript code in an environment, on a schedule, from events, or through the API.

A function runs code you write in an environment, with no agent and no model. Each start is a run. A run calls your handler with an input and saves what it returns.

Define a function

1
ellipsis:
2
kind: function
3
name: stale-pull-requests
4
5
trigger:
6
type: cron
7
schedule: '0 9 * * 1'
8
input: {days: 14}
9
10
input:
11
json_schema:
12
type: object
13
properties:
14
days: {type: integer, minimum: 1}
15
required: [days]
16
17
function:
18
handler: api-repo/functions/stale_pull_requests.py:handler
19
environment:
20
repositories:
21
- name: api-repo
22
permissions:
23
github:
24
- read_only
25
timeout: 2m
1
import json
2
import subprocess
3
from datetime import datetime, timedelta, timezone
4
5
6
def handler(context, input):
7
cutoff = datetime.now(timezone.utc) - timedelta(days=input["days"])
8
listed = subprocess.run(["gh", "pr", "list", "--json", "number,title,updatedAt"], capture_output=True, text=True, check=True)
9
stale = [pr for pr in json.loads(listed.stdout) if datetime.fromisoformat(pr["updatedAt"]) < cutoff]
10
return {"stale": stale}

Every Monday at 09:00 UTC this function lists the open pull requests in api-repo that haven't changed in 14 days, and the run saves them as its return value.

Deploy from git

Commit a .yaml or .yml file with ellipsis.kind: function anywhere under .ellipsis/ on the default branch. It appears on the dashboard's Functions page. Your organization can also keep these files in a repository named .ellipsis.

If an update is invalid, the last valid version keeps running and the function's page shows the error. Deleting the file disables the function.

POST /v1/functions creates a function without a repository file. Send the same fields as JSON under function. Each function is edited in one place, its git file or the API. Use link to move an API-created function into git, or unlink to edit a git-managed one through the API.

Write the handler

function.handler is a file and a function name joined by :. The path starts at /sandbox, so it begins with the repository name. The handler runs with that repository as its working directory.

A .py file runs on Python 3.11. A .js or .ts file runs on Node 22, which strips TypeScript types with no build step. The JavaScript handler is a named export. To run on another program, such as bun or api-repo/.venv/bin/python, set function.interpreter.

The handler is called as handler(context, input) and may be async.

  • input is the run's input, checked against input.json_schema.
  • context.function has the function's id, name, and sha.
  • context.run has the run's id, source, created_at, scheduled_at, and timeout_at.
  • context.event is the webhook that started the run, as the integration sent it. It's null for other starts.
  • context.pull_request is {"number": 42} for a run a pull_request trigger started, and null otherwise.

The handler returns a JSON object or nothing, at most 256 KiB. Set function.output.json_schema to check it. A return value that fails the schema fails the run with reason invalid_output.

For a short handler, write it in the config with function.code. function.handler then names only the file it's saved as.

1
ellipsis:
2
kind: function
3
name: add
4
5
function:
6
handler: add.py:handler
7
code: |
8
def handler(context, input):
9
return {'sum': input['a'] + input['b']}

Inline code can't import a repository's files. A handler that needs them is a file in the repository.

Start a run

Choose Run on the function's dashboard page, or start it through the API:

1
import os
2
from ellipsis import Ellipsis
3
4
client = Ellipsis(api_key=os.environ["ELLIPSIS_API_TOKEN"])
5
response = client.functions.runs.create("stale-pull-requests", input={"days": 7}, wait=True)
6
print(response.run.status, response.run.output)

A run starts in queued. With wait, the request holds for up to 45 seconds and returns the run as it is then. Without it, read the run with GET /v1/functions/{id}/runs/{run_id} until its status is final. GET /v1/functions/{id}/runs/{run_id}/logs returns what the handler wrote to standard output and standard error, the last 256 KiB.

Triggers

A function has at most one trigger. Without one, it runs only when you start it. A cron trigger starts a run on its schedule. A react trigger starts one run for each GitHub, Linear, Sentry, or Slack event it matches. Both take the same fields as an agent's triggers, plus input, the input each run starts with.

A run a pull_request event starts runs the default branch's code. It doesn't check out the pull request.

Statuses

StatusMeaning
queuedWaiting to start.
preparingIts environment is starting.
runningThe handler is running.
completedThe handler returned. output.result has the return value.
failedThe run ended with an error. error.reason says why.
cancelledThe run never ran, for example because the queue was full.

A failed run's error.reason is one of these, among others.

ReasonCause
handler_failedThe handler raised an error, or its file or function wasn't found.
timeoutThe handler ran past function.timeout.
invalid_outputThe return value isn't a JSON object, is over 256 KiB, or fails function.output.json_schema.
lifecycle_hook_failedAn environment hook failed.
queue_full100 runs were already waiting.

Limits

  • function.timeout is 1 second to 15 minutes, default 1 minute. It covers loading the file and the call.
  • An account runs up to 10 runs at once. More wait in the queue, up to 100.
  • An account starts up to 60 runs a minute. A start through the API past either limit fails with HTTP 429.
  • A run is charged for CPU and memory from when its environment starts. See Pricing.
  • An environment's mcp_servers, compute.timeout, and compute.idle don't apply to a function.
  • A GitHub permission rule in a function can't set limit or use {session_id}.

On this page

Schedule a demo
For HumansFor Agents