DaytonaDocs

FunctionService

Deploy and invoke managed serverless functions.

FunctionService deploys and invokes managed functions: you register a container handler once, then call it on demand while Daytona starts, scales, and tears down microVM instances for you and bills per invocation duration. Obtain the service as daytona.fn. For the concepts behind each method, see the functions guides — in particular deploying, invoking, and scaling.

deploy()

Deploys a function, or redeploys it as a new immutable version (upsert by name). image is a registry reference — the SDK wraps it as the version's image source. handler defaults to the image entrypoint and must start an HTTP server on port. All fields except name and image are optional; omitted values take the platform defaults.

Python
def deploy(
    name: str,
    image: str,
    handler: List[str] | None = None,
    port: int | None = None,
    vcpus: int | None = None,
    mem_mib: int | None = None,
    scratch_mib: int | None = None,
    timeout_s: int | None = None,
    scaledown_window_s: int | None = None,
    max_concurrency: int | None = None,
    max_instances: int | None = None,
    env: Dict[str, str] | None = None,
    snapshot_kind: str | None = None,
) -> Dict[str, Any]
ParameterTypeDefaultDescription
namestrPer-project unique name; [a-z0-9]([a-z0-9-]*[a-z0-9])?, 1–64 chars.
imagestrRegistry reference to boot the handler from.
handlerList[str]image entrypointArgv that starts the HTTP server on port.
portint8080Port the handler listens on (RLP_FN_PORT).
vcpusint1Provisioned vCPUs (≥ 1).
mem_mibint512Provisioned memory in MiB (≥ 128).
scratch_mibint512Scratch disk in MiB (≥ 64).
timeout_sint300Max seconds per invocation (1–172800).
scaledown_window_sint60Idle seconds before scale-to-zero (≥ 2).
max_concurrencyint1Invocations one instance serves at once (≥ 1).
max_instancesintunboundedSpend guard capping concurrent instances.
envDict[str, str]{}Environment variables for the handler.
snapshot_kindstrpre_entrypointCold-start template: pre_entrypoint or fn_ready.

Returns: a dict with the new version's details (including version and image_ref).

Python
daytona.fn.deploy(
    "greet",
    image="ghcr.io/acme/greet:latest",
    mem_mib=512,
    timeout_s=30,
    env={"LOG_LEVEL": "info"},
)

list()

Lists the project's functions, each with its current version and template state.

Python
def list() -> List[Dict[str, Any]]

Returns: a list of function summary dicts.

get()

Fetches one function's detail, including its current version and configuration.

Python
def get(name: str) -> Dict[str, Any]

Raises: DaytonaNotFoundError if the function does not exist.

invoke()

Synchronous invoke: sends payload as the JSON body and blocks until the handler responds, returning its response body. Blocks until the handler answers, the function times out, or — if no capacity is reachable within the queue budget — the call is shed with a 429.

Python
def invoke(name: str, payload: Any | None = None) -> Any
ParameterTypeDefaultDescription
namestrFunction name.
payloadAny{}JSON body forwarded to the handler's POST /.

Returns: the handler's response body (JSON-decoded).

Python
result = daytona.fn.invoke("greet", {"name": "Ada"})

spawn()

Async invoke: returns an invocation id immediately and runs the work in the background. Poll the returned id with get_invocation until it is done. See invoking for the async result-size limit.

Python
def spawn(name: str, payload: Any | None = None) -> Dict[str, Any]
ParameterTypeDefaultDescription
namestrFunction name.
payloadAny{}JSON body forwarded to the handler.

Returns: a dict with invocation_id and status.

Python
job = daytona.fn.spawn("greet", {"name": "Ada"})
inv = daytona.fn.get_invocation(job["invocation_id"])

map()

Fan-out: submits many payloads in one call as parallel invocations. Returns the invocation ids to poll individually. A single call accepts up to 1000 payloads.

Python
def map(name: str, payloads: List[Any]) -> Dict[str, Any]
ParameterTypeDefaultDescription
namestrFunction name.
payloadsList[Any]One entry per parallel invocation (≤ 1000).

Returns: a dict with invocation_ids and count.

Python
batch = daytona.fn.map("greet", [{"name": "Ada"}, {"name": "Alan"}])
for inv_id in batch["invocation_ids"]:
    inv = daytona.fn.get_invocation(inv_id)

get_invocation()

Polls a single invocation (from spawn, map, or a schedule) for its status and result.

Python
def get_invocation(invocation_id: str) -> Dict[str, Any]

Returns: a dict with status, done, cold, duration_ms, error, and result. status is one of pending, running, succeeded, failed, timeout, or shed; done is true once terminal.

Raises: DaytonaNotFoundError if the invocation does not exist.

schedule()

Creates a cron schedule that invokes the function on a recurring cadence with an optional fixed payload. The expression is a 5-field cron string in UTC. See scheduling.

Python
def schedule(name: str, cron: str, payload: Any | None = None) -> Dict[str, Any]
ParameterTypeDefaultDescription
namestrFunction name.
cronstr5-field cron expression, UTC.
payloadAnynullJSON body forwarded on each fire.

Returns: a dict with the schedule id and next_run_at.

Python
daytona.fn.schedule("nightly-etl", "0 2 * * *", {"mode": "full"})

set_public()

Enables or disables the function's public web endpoint. With require_token=True, a bearer token is minted and returned once; store it. See public endpoints.

Python
def set_public(name: str, enabled: bool, require_token: bool = False) -> Dict[str, Any]
ParameterTypeDefaultDescription
namestrFunction name.
enabledboolWhether the public endpoint is on.
require_tokenboolFalseRequire a per-function bearer token.

Returns: a dict with url, requires_token, and (once) token.

Python
result = daytona.fn.set_public("webhook", enabled=True, require_token=True)
print(result["url"], result["token"])

On this page