Long-running tasks

A single exec call is bounded: the sandbox exec endpoint accepts a timeout of 1 to 86,400 seconds (default 3,600), independent of the sandbox’s own timeout. Work that runs longer - a dev server, a build, a watcher, a worker - should be started as a background process and inspected separately.

Start a background process

The body accepts cmd (required), cwd, env, and name. The sandbox must be running to start a process.

Check status and logs

StatusMeaning
runningProcess is alive
exitedProcess exited normally
killedProcess was stopped via DELETE
errorProcess failed to start

Fetch the last N lines of stdout+stderr, or stream them live:

# Last 50 lines
curl "https://api.miosa.ai/api/v1/sandboxes/sbx_abc123/processes/proc_01hwxyz/logs?tail=50" \
  -H "Authorization: Bearer $MIOSA_API_KEY"

# Live stream (SSE)
curl "https://api.miosa.ai/api/v1/sandboxes/sbx_abc123/processes/proc_01hwxyz/stream" \
  -H "Authorization: Bearer $MIOSA_API_KEY"

Stop a process with DELETE, which sends SIGTERM and then SIGKILL after a grace period.

Daemons for long-lived services

A sandbox daemon is a named long-lived process: start it once, then list it, read its output and restart or stop it by name instead of hunting for a pid.

miosa daemon create my-box --name web --command "npm run dev" --cwd /workspace/app
miosa daemon list my-box
miosa daemon logs my-box web
miosa daemon restart my-box web
miosa daemon stop my-box web

The same calls are POST /api/v1/sandboxes/:id/daemons, GET .../daemons and GET .../daemons/:name; the Processes API documents the process model they sit on.

On Computers, long-lived daemons belong to systemd and restart on failure rather than to a process table; see the Services API.

Keep a sandbox alive

A background process only runs while the sandbox does. Two settings control that:

  • always_on: true disables timeout and idle-timeout enforcement until an explicit lifecycle action, subject to tenant policy.
  • idle_timeout_sec stops an abandoned persistent session after a period of inactivity; 0 disables idle auto-stop. Left unset, it defaults to 0, or 1800 (30 minutes) for accounts created on or after October 11, 2026. A stopped sandbox wakes on the next request.

The timeout is idle-anchored. For persistent sandboxes, expiry stops the sandbox rather than destroying it, and a stop never keeps running processes. Explicitly non-persistent sandboxes are destroyed. See Timeouts and auto-stop.

See also

Was this page helpful?