Skip to Content
Xeonr Developer Docs

Jobs

Run-to-completion workloads — argv, stdin, input files, collected outputs, streamed logs.

A job creates a pod, runs argv, produces outputs and terminates. It is the primitive behind pipeline steps, codegen plugins and batch work.

Running one

RunJob is a server stream. The first event is always accepted, carrying the job id — so a caller that loses the stream (a closed tab, a restarted worker) can still find the run.

const run = await cp.jobs.run({
  environment,
  argv: ["ffmpeg", "-i", "/work/in.mp4", "-vf", "scale=320:-1", "/work/out.gif"],
  label: "thumbnail",
  resources: { cpu: "2", memory: "2Gi", ephemeral: "4Gi", pids: 256 },
  timeout: "5m",
}, {
  onAccepted: (jobId) => console.log("job", jobId),
  onState: (state) => console.log(state),
  onLog: (chunk) => process.stdout.write(chunk.text),
});

console.log(run.exitCode, run.terminationName);

run() drains the stream and hands back the outcome; the callbacks are optional. cp.jobs.stream(spec) gives you the raw event sequence instead.

A caller that cannot hold a stream starts the same job with the unary CreateJob, which takes the RunJobRequest as spec and returns the job_id as soon as the job is admitted; the job then runs exactly as one started with RunJob. A repeated idempotency_key returns the earlier job's id with existing: true. Follow it with GetJob and GetJobLogs. Guarded setup jobs (execution_sandbox_id) are started with RunJob only.

argv is argv — the platform never shell-joins it. If you want a shell, ask for one explicitly: ["bash", "-lc", "..."]. Omitting argv runs the environment's default_argv, or the image entrypoint.

States are QUEUED → RUNNING → SUCCEEDED | FAILED | CANCELLED. The result carries exit_code, a status-derived termination, captured stdout, collected outputs, and usage. A job its timeout stops ends with TERMINATION_TIMEOUT. If the workload had started, exit_code is what it exited with when it was killed (usually 137); if it never started, such as when its pod could not mount a volume before the timeout, exit_code is -1. Either way termination_reason gives the Kubernetes reason code: DeadlineExceeded, or for a workload that never started the reason it was held, such as FailedMount.

Files in and out

The job's scratch is /work, and that is where both directions land.

Inputs are seeded by an init container before the workload starts. Every path is confined under /work; traversal out of it fails the pod closed.

inputs: {
  "in.mp4": bytes,                                  // inline content
  "seed.json": new URL("https://example.test/seed"), // fetched by the agent
}

Outputs are declared, and the agent collects them from /work after the workload exits, inside the pod's termination grace window:

outputs: [
  { name: "gif", path: "out.gif", maxBytes: 8_000_000, required: true },
]

Read them back off the outcome: run.outputs (each with content or uploadedTo), and run.kv for the /out/.kv.json convention.

They come back as Artifacts on the result with sha256, size and content. A missing non-required output is skipped rather than failing the run.

stdin is delivered as a file and redirected onto fd 0 by wrapping the command (exec "$@" < /work/.cp-stdin). Two consequences worth knowing: the image needs a shell, and a job with no argv — running the image entrypoint — cannot be wrapped and so gets no stdin.

For anything bigger, or anything that should outlive the run, attach a workspace with workspace_id and use /workspace instead.

Reading a job's filesystem while it runs

filesystemApi: true serves the container file API against a running job — useful for watching a build write its cache, or reading a log it has not flushed anywhere yet:

const outcome = await cp.jobs.run({
  environment,
  argv: ["./build.sh"],
  filesystemApi: true,
});

// from another task, while it runs:
await cp.jobs.fs(jobId).readText("/work/build.log");

It is opt-in because it forces the agent sidecar onto a job that may need no egress, no workspace and no outputs, and runs the workload under the supervisor.

It is also only reachable while the job is RUNNING — the pod is torn down at completion and its filesystem goes with it. This does not replace outputs: anything that must survive the run still has to be declared and collected before the pod goes away.

Environment variables

env lands on the pod spec. That makes it readable by anything that can describe pods in the runner namespace — it is not a secret channel.

Names the platform owns are rejected loudly rather than silently overridden: anything prefixed CP_, the proxy variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY and lowercase forms), JAVA_TOOL_OPTIONS, and the TLS trust-store variables (SSL_CERT_FILE, CURL_CA_BUNDLE, GIT_SSL_CAINFO, REQUESTS_CA_BUNDLE, PIP_CERT, NODE_EXTRA_CA_CERTS). Overriding those would break proxy discovery or terminating egress rules in ways that present as "the network hangs for no reason".

Adapter containers

When a product needs credentials next to untrusted code — the pattern behind upl.im's pipeline steps — run them in an adapter: a second container sharing /work and the pod's network namespace, holding the credentials the workload must never see.

adapter: {
  environment: adapterEnvironment,   // an Environment in the same namespace
  env: { UPL_INTERNAL_TOKEN: "..." },
  cpu: "200m",
  memory: "256Mi",
},
secrets: {
  "step-token": token,
},

The SDK refuses secrets without an adapter rather than dropping them: they are mounted into the adapter alone, so with no adapter there is nothing to mount them into, and a caller who believes their credential reached the job is worse off than one who got an error.

secrets are written as mode 0400 files into the adapter only — never the workload, never the pod spec, never the job record. They live in a Kubernetes Secret owned by the pod and are garbage-collected with it. The workload reaches the adapter over 127.0.0.1, which is also what keeps the pod gVisor-compatible (shared-emptyDir Unix sockets don't cross containers under runsc).

Waiting for the adapter

By default the workload starts as soon as the adapter's process has started, alongside it. An adapter that prepares /work before the workload may run (stages inputs, injects a binary) declares a startup check, and the workload then starts only once that check has passed, so the workload's image needs no shell to wait with. On the wire it is AdapterContainer.startup:

"adapter": {
  "environmentId": "env-…",
  "startup": {
    "exec": { "argv": ["/app/sidecar", "ready"] },
    "timeoutSec": 600,
    "periodSec": 1
  }
}

The check is either exec (a command in the adapter's image; ready on exit 0) or tcpPort (ready once the port accepts a connection on the pod's address). It runs every periodSec (default 2, at most 30) from the adapter's start. If it has not passed within timeoutSec (default 60, at most 3600; image pull time is not counted) the job ends before the workload runs, with termination TERMINATION_ADAPTER_FAILED and termination_reason AdapterNotReady. As with services, the job's own timeout_sec starts when the workload starts. A cluster whose operator cannot render the check refuses the job with FAILED_PRECONDITION rather than running it ungated.

Service containers

A job can run up to four services beside its workload: a database for its tests, a cache, a mock server. Each runs in the job's pod for as long as the job does, and shares the pod's network namespace, so the workload reaches it at 127.0.0.1 or by its name. The SDK does not wrap them yet; on the wire they are RunJobRequest.services:

"services": [{
  "name": "mysql",
  "environment_id": "env-0123456789abcdef",
  "env": { "MYSQL_ALLOW_EMPTY_PASSWORD": "1", "MYSQL_DATABASE": "app" },
  "cpu_millis": 1000,
  "memory_mb": 1024,
  "readiness": { "exec": { "argv": ["mysqladmin", "ping", "-h", "127.0.0.1"] }, "timeout_sec": 90 }
}]
FieldNotes
nameA DNS label, unique in the job, and the hostname the workload uses. Two services cannot listen on the same port
environment_idAn Environment in the same namespace, registered like the workload's, on the same runtime as the job's. Its run_as_root and writable_rootfs are honoured exactly as they would be for a step in this namespace (a database image usually needs writable_rootfs); nested_containers is refused
command, argsReplace the image's ENTRYPOINT and CMD. With neither, the environment's default_argv runs, else the image's own
envLike the workload's: on the pod spec and the job record, not a secret channel, and the platform's names are refused
cpu_millis, memory_mb, ephemeral_mbDefault 500, 512 and 1024. A job's services total at most 8000 millicores and 16384 MiB, additional to the workload and counted against the namespace quota
readinessOptional. exec runs a command in the service (ready on exit 0); tcp_port connects to the pod's address, so the service must listen on 0.0.0.0, not only on loopback. timeout_sec (default 60, at most 600) counts from the service's start, not its image pull; period_sec defaults to 2

Start order. Services start in list order, before the workload. A service with a readiness check holds back everything after it until the check passes, so the workload starts only once every checked service is ready; one without a check is up as soon as its process has started.

When something goes wrong. A service whose image cannot be pulled, or whose check has not passed within its wait, ends the job before the workload runs: termination is TERMINATION_SERVICE_FAILED and termination_reason is ServiceImagePullFailed or ServiceNotReady. Once the workload is running, a service that exits is restarted and never decides the job's result. When the workload ends, the services are stopped.

Timeout. A job with services starts counting its timeout_sec when its workload starts, not when its pod is created, so a slow service is not charged to the step. Until then the job is bounded by its timeout plus every service's readiness wait.

Status and logs. JobResult.services has one entry per service: outcome (NOT_STARTED, IMAGE_PULL_FAILED, NOT_READY, RUNNING for the normal case, or EXITED), started, ready, exit_code and reason of its last exit, restarts, and log_tail, the last 64 KiB of its output. A service's output is never part of the job's log.

Isolation. Services run under the job's runtime (gVisor by default), the platform's hardened security context, the job's egress policy and the namespace's pull secrets. They mount none of the job's workspaces, never see the adapter's secrets, and each gets its own /tmp.

Services are not served from a warm pool (a job with services always cold-starts), are not accepted on a guarded setup job, and need the cluster's operator to support them: on an older one the job is refused with FailedPrecondition.

Idempotency and callbacks

idempotency_key claims a key per namespace: a repeat with the same key returns the original job rather than starting a second one.

callback gives the platform somewhere to POST when the job reaches a terminal state — useful when the caller is a workflow engine that doesn't want to hold a stream:

{
  "job_id": "...",
  "namespace": "my-app",
  "state": "JOB_STATE_SUCCEEDED",
  "exit_code": 0,
  "termination": "TERMINATION_EXITED"
}

A job that ended for a Kubernetes reason also carries termination_reason, the same reason code as on the job's result (for example "DeadlineExceeded" or "FailedMount"). It is left out when there is none.

The token is sent as Authorization: Bearer. The endpoint must be http(s), and is resolved and pinned to a validated public IP before dialling — private, loopback and link-local targets are refused, and there is no rebind window between the check and the dial.

Logs, listing and cancellation

CallNotes
TailLogsStreams the log, live for a running job and from the stored copy for an ended one; from_offset resumes exactly where a previous read stopped
GetJobLogsOne bounded read without a stream: the last 64 KiB by default (limit_bytes up to 1 MiB), or forward from from_offset (or from_start), with next_offset and more for the next read
GetJobThe record, including spec — the full request readback, so a run can be faithfully repeated
ListJobsFilter by namespace, environment and state; paginated
CancelJobTerminal state becomes CANCELLED

A job's log is its stdout and stderr interleaved in the order written. Every log chunk, on RunJob, TailLogs or GetJobLogs, carries offset: the byte position of its first byte in that log, with stderr marking stderr bytes. Resume from offset + len(data) of the last chunk you kept. An ended job keeps the first 256 KiB of each stream, and JobResult.log_spans records how they interleave; where a stream was cut the offsets jump, so a gap in the stored log is visible rather than silent.

Job.spec deliberately excludes the things that must not be replayed or read back: idempotency_key (a re-run must mint a fresh run), secrets, and the adapter's env. It keeps services whole.

Warm pools

Set pool_lane to route a job at a pre-warmed pod, cutting cold-start latency. If the lane has no idle pod — or no pool is configured — the job falls back to a cold start. See Warm pools.

Network

A job's default egress is MODE_NONE: no DNS, no route out. Pass egress (inline or by policy id) to change that.

egress: egress.allowlist("my-bucket.s3.example.com")

Or egress.presets("npm"), or a named policy's id.

The job's policy is control-plane state for exactly the length of its run. See Egress.

On this page