A function is code you deploy to Maton and call over HTTP. It gets its own URL, runs in an isolated sandbox, and can access your connected apps through the gateway.
The parts of a function
Name and URL
The name identifies the function and determines its URL (eg. my-fn → https://my-fn-3k9xq2v.maton.app). Renaming a function reallocates its URL, so update anything pointing at the old one.
Runtime
The runtime executes the handler (eg. python3.12). It is fixed when the function is created.
Version
Every code update publishes a new version. The latest version serves traffic, and older ones stay available so you can download their code or roll back to them.
Visibility
The visibility controls who can find the function. PRIVATE keeps it to your account, and functions shared publicly are discoverable by others through function search.
Network policy
The network policy controls whether the sandbox may reach the network. ALLOW_ALL (the default) lets the handler make outbound requests, and DENY_ALL blocks every one of them.
Environment
Environment variables hold the configuration and secrets your handler reads at runtime, so you can keep them out of the code and change them without deploying a new version. Each variable is either PLAIN or SENSITIVE (default when omitted). Alongside those variables, the sandbox injects a MATON_API_KEY scoped to the owner account.
Handler
The runtime calls the handler with an event and an optional context, and turns its return value into an HTTP response. The handler is named <file>.<symbol> without the file extension, and defaults to main.handler on Python and index.handler on Node.
def handler(event, context):
return {"hello": "ada"}export function handler(event, context) {
return { hello: 'ada' }
}Event
The event describes the incoming HTTP request. The body arrives as a string, so parse it yourself.
{
"version": 1,
"rawPath": "/",
"rawQueryString": "a=1",
"cookies": ["k=v"],
"headers": { "host": "my-fn-3k9xq2v.maton.app" },
"queryStringParameters": { "a": "1" },
"requestContext": {
"accountId": "{account_id}",
"domainName": "my-fn-3k9xq2v.maton.app",
"domainPrefix": "my-fn-3k9xq2v",
"http": {
"method": "POST",
"path": "/",
"protocol": "HTTP/1.1",
"sourceIp": "203.0.113.7",
"userAgent": "maton/0.3.0"
},
"runId": "{run_id}",
"time": "30/Aug/2026:17:24:03 +0000",
"timeEpoch": 1788000000000
},
"body": "{\"name\":\"ada\"}",
"isBase64Encoded": false
}Context
The optional context carries the identity of the function and the current run.
context.run_id # "{run_id}"
context.function_name # "my-fn"
context.function_version # "1"
context.function_id # "{function_id}"
context.account_id # "{account_id}"
context.memory_limit_in_mb # 128context.runId // "{run_id}"
context.functionName // "my-fn"
context.functionVersion // "1"
context.functionId // "{function_id}"
context.accountId // "{account_id}"
context.memoryLimitInMB // "128"Response
Anything the handler returns that is not a dict carrying a statusCode key is
sent as the response body with a 200. A returned string is JSON-encoded, so
return "hello" comes back as "hello" with the quotes. To set the status or
headers, return an envelope carrying statusCode instead:
def handler(event, context):
return {
"statusCode": 201,
"headers": {"content-type": "text/plain"},
"body": "created",
}Common Questions
No. The sandbox injects a MATON_API_KEY scoped to the owner account at runtime, so the SDK and the gateway work out of the box. Use environment variables only for third-party secrets your own code needs.
Check its network policy. DENY_ALL blocks all outbound requests from the sandbox, including calls to the gateway. Switch it to ALLOW_ALL and the change applies on the next run.
Each code update publishes a new version and the latest one starts serving traffic. Older versions stay available, so you can download their code or roll back by pointing the function at an earlier version.
Yes. The URL is derived from the name, so renaming reallocates it. Update any triggers, webhooks, or clients that call the old URL.
Next
Managing functions
Create, deploy, update, and delete your functions from the Console, CLI, or an AI agent.
Managing environment
Store the configuration and secrets your handler reads at runtime.
Managing runs
Invoke a function, inspect each run's request and response, and read its logs.
Triggers
Subscribe to events from a connected app and deliver each one to your function.