Time Portal · Sandbox
Commands and Files
A command is a program you start in a live sandbox. The files endpoints read and write the sandbox's filesystem.
Start a command
POST/v1/time-portal/sandbox/{id}/execs starts a program in a live sandbox. It is asynchronous: it returns the command's id once the command has started, not when it ends. Send an Idempotency-Key so a retried request returns the same command instead of starting a second one. The command sees the sandbox's clock and network, both set to the sandbox's as_of; see How the Instant Works.
JSON
json
{
"argv": ["python3", "-c", "import datetime; print(datetime.date.today())"],
"env": {"PYTHONUNBUFFERED": "1"},
"timeout": "10m",
"stdin_b64": "",
"stdin_open": false
}argvis the program and its arguments, up to 1,024 of them and 128 KiB, withPATHset but no shell: to use pipes or&&, run["sh", "-c", "…"]. A program that does not exist is an exit of 127, not an error.- Commands run as
root, in/home/epochal, root's home, unlesscwdsays otherwise; a directory that does not exist is an exit of 2, not an error.envadds up to 128 variables, 32 KiB, on top of the sandbox's own. timeoutkills the command after this long,1hwhen unset and at most24h.stdin_b64is the first bytes of standard input, at most 1 MiB decoded; upload larger inputs as a file. Stdin is closed after it unlessstdin_openis true, which keeps it open for laterinputrequests; bytes sent after it closes are dropped.
Several commands can run in one sandbox at once, and a running command keeps the sandbox from going idle.
Read output
GET …/execs/{exec_id}/output returns frames of output, in stream order, and exit once the command has ended.
JSON
json
{
"frames": [
{"stream": "stdout", "offset": 0, "data_b64": "MjAyNi0wMy0wMQo="}
],
"exit": {"reason": "exited", "code": 0}
}- Each frame is base64 bytes from
stdoutorstderrwith theoffsetof its first byte in that stream. Passstdout_offsetandstderr_offsetto ask for what came after what you have. waitholds the request for up to55suntil there is new output or the command exits, so a polling loop does not spin. A poll can return output and noexit.max_bytescaps the output bytes returned across both streams per poll, at most 4 MiB, which is also the default.exitis set only once every frame up to the end is inframes; until then, poll again from the end of each stream's last frame. Decode once at the end: a frame can end inside a multi-byte character.- Output is kept only while the sandbox is
live. Once the sandbox ends, reading output is a409, so read a command to itsexitbefore the sandbox ends.
Check the exit reason
exit.reason | Meaning |
|---|---|
exited | Process exited normally; code is its exit status. |
signaled | Process terminated by a signal; signal is the POSIX signal number. |
out_of_memory | Process exceeded the sandbox memory limit. |
timeout | Command exceeded its timeout. |
sandbox_ended | The sandbox terminated while the command was running. |
lost | The sandbox host stopped reporting command status. |
Write input
POST …/execs/{exec_id}/input sends stdin bytes, closes stdin, or sends a signal:
JSON
json
{"seq": 0, "data_b64": "aGVsbG8K"}
{"seq": 1, "eof": true}
{"seq": 2, "signal": 15}seq counts this command's input requests from 0. A retried request with the same seq is applied once, and a request out of order is a 409 conflict whose error carries next_seq; resend with that seq.
Each request does one thing: data_b64, eof, or signal. Each data_b64 is at most 1 MiB decoded; upload larger inputs as a file and have the command read it. Input to a command that has exited is a 409. For every 409 case on a command, see Errors.
Install packages
With network: "time-portal", apt, pip, uv, and npm install from mirrors set to as_of; Images and Network says what is already installed. With network: "none", upload what you need as files.
Files
The five endpoints under /v1/time-portal/sandbox/{id}/files all take absolute paths inside the sandbox.
| Endpoint | Behavior |
|---|---|
PUT …/files?path=&offset= | Writes raw request bytes (up to 8 MiB per request) at offset, creating missing parent directories. offset=0 replaces the file; upload larger files in sequential chunks at advancing offsets. Returns the updated file stat. |
GET …/files?path= | Reads a byte range (Range: bytes=<first>-<last> or bytes=<first>-, up to 64 MiB; defaults to the first 16 MiB). Returns 206 with Content-Range: bytes <first>-<last>/<size>, 200 for an empty file, 416 if the range starts past EOF, or 400 for suffix/multi-range headers. |
DELETE …/files?path=&recursive= | Deletes a file or empty directory, or a directory tree when recursive=true. Non-empty directories without recursive=true return 400. |
GET …/files/stat?path= | Returns type (file, directory, symlink, other), size, mode, mtime (sandbox clock), and link_target. |
GET …/files/list?path=&recursive=&limit= | Returns paginated directory entries with relative path values (default 50, max 100). Pass next_cursor as cursor for the next page. |
A write or a remove counts as activity for idle_timeout. A read, a stat, or a list does not.
Files live only as long as the sandbox. There is no persistent volume: download what you need to keep before the sandbox ends.
Next steps
A sandbox boots, runs while it is live, and ends at a timeout, a terminate, or a failure.
A sandbox boots the Ubuntu build chosen by its instant and reaches only what its network setting allows.
A sandbox is a Linux virtual machine whose clock and network are set to an instant.