A Python client for the redu.cloud API. Version 0.1 covers sandboxes: isolated machines started from a template, for
running commands. It is the Python twin of the TypeScript SDK (redu-sandbox-sdk-ts): the same routes, the same
retry rules, idiomatic Python.
- Python 3.9 or later. One dependency:
httpx. - A sync client (
Redu) and an async client (AsyncRedu) with the same methods and the same behaviour. - Typed: answers are dataclasses, errors are
ReduErrorsubclasses, and the package shipspy.typed. - Apache-2.0 licensed (see "License").
An account that sandboxes are not open to gets 403 sandboxes_not_available on every sandbox route;
redu.sandboxes_enabled() tells whether they are open to yours. The documentation of the service is at
https://docs.redu.cloud/Services/sandboxes.
pip install redu-sandbox-sdkThe distribution is redu-sandbox-sdk; the package you import is redu_sandbox.
from redu_sandbox import Redu
redu = Redu() # the API key from REDU_API_KEY
sandbox = redu.sandboxes.create("ubuntu-node", timeout_s=600)
try:
result = redu.sandboxes.exec(sandbox.id, "node -v")
print(result.exit_code, result.stdout)
finally:
redu.sandboxes.delete(sandbox.id)| Argument | Sent as | Notes |
|---|---|---|
api_key |
Authorization: Bearer |
The key needs sandbox:*, or the route's own sandbox:<action>. A full-access * key does not include sandboxes: 403 insufficient_scope. |
token |
Authorization: Bearer |
A signed-in session's access token. Pass a function to hand a fresh token to each request (an async function works with AsyncRedu). |
Give one of them. With neither, the client reads REDU_API_KEY from the environment. base_url defaults to
REDU_API_BASE, else https://console.redu.cloud.
redu.sandboxes_enabled() tells whether sandboxes are on for the caller's account (from GET /v1/capabilities).
| Method | Route | Returns |
|---|---|---|
templates() |
GET /v1/sandboxes/templates |
list[Template] (name, vcpus, memory_mb, disk_gb, price) |
list() |
GET /v1/sandboxes |
your live sandboxes |
get(id) |
GET /v1/sandboxes/{id} |
one Sandbox |
create(template, ...), create(snapshot=..., ...) |
POST /v1/sandboxes |
the Sandbox once it is running |
exec(id, command, ...) |
POST /v1/sandboxes/{id}/exec |
ExecResult: exit code, stdout, stderr |
delete(id) |
DELETE /v1/sandboxes/{id} |
returns once it is gone |
add_public_name(id, port, domain=None) |
POST /v1/sandboxes/{id}/dns |
PublicName (id, domain, port, url) once it serves |
remove_public_name(id, dns_id) |
DELETE /v1/sandboxes/{id}/dns/{dns_id} |
returns once it no longer serves |
open_terminal(id, cols=, rows=, idle_timeout_s=) |
POST /v1/sandboxes/{id}/terminal |
a websocket TerminalSession (url, token, ...), or the web Terminal (url, username, password) |
close_terminal(id) |
DELETE /v1/sandboxes/{id}/terminal |
TerminalClosed: what the stop found, platform_terminals included |
get_lifecycle(id) |
GET /v1/sandboxes/{id}/lifecycle |
SandboxLifecycle: its idle pause, its end and its spend in one view |
set_lifecycle(id, timeout_s=, max_spend=, idle_pause_s=) |
PUT /v1/sandboxes/{id}/lifecycle |
LifecycleChanged: the lifecycle after the change, and changed |
limits() |
GET /v1/sandboxes/limits |
SandboxLimits: the account's limits, what is used and what is left |
list_ended(limit=None, cursor=None) |
GET /v1/sandboxes?state=ended |
EndedSandboxPage: the sandboxes that ended in the last 7 days, and next_cursor |
get_ended(id) |
GET /v1/sandboxes/{id}?state=ended |
one EndedSandbox |
build_template(name, image, ...) |
POST /v1/sandboxes/templates/builds |
the TemplateBuild, once accepted (queued) |
list_template_builds() |
GET /v1/sandboxes/templates/builds |
your builds, newest first |
get_template_build(build_id) |
GET /v1/sandboxes/templates/builds/{build_id} |
one TemplateBuild, with its log |
cancel_template_build(build_id) |
DELETE /v1/sandboxes/templates/builds/{build_id} |
TemplateBuildCancel: cancelling, finishing, forgotten or pending |
delete_template(template_id) |
DELETE /v1/sandboxes/templates/{template_id} |
returns once it is gone |
set_secrets(id, secrets), remove_secrets(id) |
PUT, DELETE /v1/sandboxes/{id}/secrets |
SandboxSecrets: names and hosts, never a value |
get_ssh(id) |
GET /v1/sandboxes/{id}/ssh |
SandboxSsh: its SSH server, keys, host keys and how to connect |
add_ssh_key(id, key), remove_ssh_key(id, fingerprint), remove_all_ssh_keys(id) |
POST, DELETE /v1/sandboxes/{id}/ssh/keys |
the SandboxSsh after the change |
open_ssh(id, idle_timeout_s=None) |
POST /v1/sandboxes/{id}/ssh |
SshSession: one connection (url, token, known_hosts, a ready ssh command) |
extend(id, timeout_s) |
POST /v1/sandboxes/{id}/extend |
ExtendedSandbox: the sandbox with its new expires_at |
pause(id), resume(id), suspend(id) |
POST /v1/sandboxes/{id}/pause, /resume, /suspend |
SandboxStateResult (status, already, from_, expires_at) |
read_file(id, path) |
GET /v1/sandboxes/{id}/files?path= |
the bytes of a file of at most 8 MiB |
read_file_range(id, path, offset=0, length=None) |
the same, with a Range |
one FileRange (data, offset, next, size) |
iter_file_ranges(id, path), read_large_file(id, path) |
the same, part after part | each part as it comes, or the whole file |
write_file(id, path, data, mode=None) |
PUT /v1/sandboxes/{id}/files?path= |
WrittenFile (path, bytes) |
start_command(id, command, ...) |
POST /v1/sandboxes/{id}/commands |
StartedCommand, running in the background |
list_commands(id) |
GET /v1/sandboxes/{id}/commands |
the running ones and the last 32 that ended |
get_command(id, command_id, ...) |
GET /v1/sandboxes/{id}/commands/{command_id} |
CommandOutput: the command and its output past the offsets |
follow_command(id, command_id), wait_for_command(...) |
the same, until it ends | its output as it comes, or CommandEnd with all of it |
stop_command(id, command_id, signal="TERM") |
DELETE /v1/sandboxes/{id}/commands/{command_id} |
the Command, signalled |
take_snapshot(id, name=None) |
POST /v1/sandboxes/{id}/snapshots |
the Snapshot once it is taken |
list_snapshots() |
GET /v1/sandboxes/snapshots |
your snapshots, oldest first |
get_snapshot(snapshot_id) |
GET /v1/sandboxes/snapshots/{snapshot_id} |
one Snapshot |
delete_snapshot(snapshot_id) |
DELETE /v1/sandboxes/snapshots/{snapshot_id} |
returns once it is gone |
fork(id, name=, timeout_s=, env=, max_spend=, idle_pause_s=) |
POST /v1/sandboxes/{id}/fork |
the new Sandbox, a running copy |
change_egress(id, egress) |
PUT /v1/sandboxes/{id}/egress |
EgressChanged (id, egress, connections_closed) once the sandbox has the new rules |
egress_log(id, since=0, limit=None) |
GET /v1/sandboxes/{id}/egress/log |
one EgressLogPage (events, next_since, more) |
iter_egress_events(id, since=0) |
the same, page after page | each EgressEvent, to the log's end |
resize(id, vcpus=None, memory_mb=None) |
POST /v1/sandboxes/{id}/resize |
ResizedSandbox: at its new size, with resized_from, resized_to, price |
audit_log(id, since=0, limit=None, kind=None) |
GET /v1/sandboxes/{id}/audit |
one AuditLogPage (events, next_since, more) |
iter_audit_events(id, since=0, kind=None) |
the same, page after page | each AuditEvent, to the log's end |
verify_audit_chain(events, after=None, chain=True) |
none: a check run here | AuditChainResult (ok, checked, withheld, last, problem) |
get_request(workflow_id) |
GET /v1/sandboxes/requests/{workflow_id} |
one read of a request that answered 202 |
wait_for_request(workflow_id) |
the same, until it ends | how it ended |
Every answer keeps redu's whole JSON object in .raw, so a field redu adds later is never lost.
Extend, pause, suspend, resume, files and background commands need the redu API version that adds them (the API of
20 Nov 2026). An API from before answers them 404 not_found. Snapshots, fork, egress rules and the connection log need
the later API version of 20 Nov 2026 that adds them: an API from before answers their routes 404 not_found (the
snapshot list 400 validation_error, as it reads snapshots as a sandbox id) and refuses snapshot or egress in a
create (400 validation_error). A create's size and network_id, resize and the audit log need the API version of
21 Nov 2026: an API from before answers their routes 404 not_found and refuses the new create fields
(400 validation_error). change_egress, a create's volumes, a sandbox's resize_range and the storage prices need
the later API version of 21 Nov 2026: an API from before answers the change 404 not_found, refuses volumes
(400 validation_error), and leaves the new fields None. A sandbox's lifecycle, the limits, ended sandboxes, templates
built from container images, secrets, SSH and the terminal over the platform's websocket need the API version of
27 Nov 2026: an API from before does not know their routes (404 not_found; a read whose path it takes for a sandbox's
id, such as the limits, 400 validation_error) and refuses idle_pause_s or secrets in a create
(400 validation_error). A sandbox with no end (timeout_s=0), the free sandbox (free) and the limits'
max_lifetime_s, no_end and free_sandbox need the API version of 1 Dec 2026: an API from before refuses
timeout_s=0 and free (400 validation_error), and those three fields read None. In AsyncRedu, iter_file_ranges,
follow_command, iter_egress_events and iter_audit_events are async iterators (async for).
sandbox = redu.sandboxes.create(
"ubuntu-node", # a name or id from templates()
name="build-42", # optional
timeout_s=3600, # 60 up to your longest life, or 0 for no end (see "Lifetime"); default 3600
env={"NODE_ENV": "test"}, # optional
public=True, # optional: it can then have public names and a web terminal
)redu answers 201 once the sandbox is running. When it is still being made after about 40 seconds, redu answers 202
with a workflow_id, and the client waits for it through GET /v1/sandboxes/requests/{workflow_id}. Pass
wait=False to get the 202 back instead (a PendingRequest), and read it later with get_request or
wait_for_request.
The client never sends a create twice by itself: a create whose answer was lost may still be running, and a second
one makes a second sandbox (list() shows the first one once it is ready). An idempotency_key lets you repeat a
create safely once the first one has answered: redu stores that answer for the key for 24 hours.
Instead of a template, snapshot= starts the sandbox from a snapshot of yours (see "Snapshots"). Give exactly one of
the two: both, or neither, is refused with ValueError before anything is sent.
From a template, a create can also set the sandbox's size, each left out for the template's own: vcpus (1 to 4),
memory_mb (1024, 2048, 4096 or 8192: SANDBOX_MEMORY_MB) and disk_gb (at least this much disk, 1 to 10). A vCPU count or memory
size other than the template's takes the slower path (seconds rather than a fraction of one). Every read shows the
sandbox's vcpus, memory_mb and disk_gb, the size it is billed at. 400 size_unsupported (the template cannot be
made at that size), 409 quota_exceeded (your sandbox limits cannot hold it now). A sandbox made from a snapshot has
the snapshot's size: a size with snapshot= is refused with ValueError before sending.
big = redu.sandboxes.create("ubuntu-node", vcpus=2, memory_mb=2048, disk_gb=8)
print(big.vcpus, big.memory_mb, big.disk_gb)network_id= (an id from GET /v1/private_networks) puts the sandbox on one of your private networks, so it reaches
your machines there; all its traffic leaves through that network, and sandbox.network_id names it. It gets a
security group of its own that lets nothing in, and it is not public (no public names, no terminal). public=True and
network_id do not go together: both are refused with ValueError before sending. 404 network_not_found, 409 network_unusable (no IPv4 subnet), 409 security_group_quota_exceeded.
volumes= attaches and mounts one or two of your volumes (SANDBOX_VOLUMES_MAX), from a template only: with
snapshot= it is refused with ValueError before sending. Each is a VolumeInput(id, mount_path=None, format=None) or a
dict as the API takes it: id from GET /v1/volumes/list; mount_path an absolute path outside the system's own
directories (default /mnt/volumes/<id>, no two at the same place or one inside the other); format (default True)
formats a volume with no filesystem, partition table or other signature, so its data is gone, and mounts one with a
signature as it is (False: a volume with none fails the create). Every read shows volumes, a list of
SandboxVolume(volume_id, mount_path, status). When the sandbox is deleted, or ends, its volumes are detached and keep
their data; a volume keeps its own price while attached. A sandbox with volumes cannot be snapshotted, forked or
suspended (409 sandbox_has_volumes: pause it instead). An API key needs volume:attach or volume:* beside its
sandbox scope (403 insufficient_scope).
from redu_sandbox import VolumeInput
volume_id = "5f0c6a7e-1b2d-4c3e-8f40-0123456789ab" # an id from GET /v1/volumes/list
with_data = redu.sandboxes.create("ubuntu-node", volumes=[VolumeInput(volume_id, mount_path="/work", format=False)])
print(with_data.volumes) # [SandboxVolume(volume_id=..., mount_path='/work', status='attached')]| Code | What it means |
|---|---|
404 volume_not_found |
no such volume in your account |
409 volume_in_use |
it is attached to something else: a machine or another sandbox |
409 volume_not_available |
it is being made, changed or deleted, or it failed |
400 volume_unsupported |
it is encrypted, or it can be attached to several machines at once |
400 too_many_volumes |
the template takes fewer volumes |
409 volumes_unavailable |
volumes cannot be attached to sandboxes yet on this cloud |
502 volume_attach_failed |
VolumeAttachFailedError: they could not be attached, no sandbox was made, and the volumes stay available |
In each of them nothing was made.
A create also takes idle_pause_s (see "Lifecycle"), secrets (see "Secrets") and free (see "The free sandbox").
egress at create limits the connections a sandbox may open. Rules are tried in order and the first match decides;
default_action decides the rest. Left out, everything is allowed.
from redu_sandbox import EgressPolicy, EgressRule
locked = redu.sandboxes.create(
"ubuntu-node",
egress=EgressPolicy("deny", [
EgressRule("allow", hosts=["pypi.org", "*.pythonhosted.org"], ports=[443]),
EgressRule("allow", cidrs=["198.51.100.0/24"], ports=["5432", "8000-8999"]),
]),
)
print(locked.egress) # SandboxEgress(default_action, rules, updated_at), as redu normalized themA rule gives hosts or cidrs (not both: write two rules), with ports or not, or ports alone; a rule that breaks
this is refused with ValueError before anything is sent. A host rule matches the name a TLS or HTTP connection carries:
an exact name, or *.example.com for every name under it. cidrs are IPv4 networks; ports are numbers or ranges
("8000-8999"). At most 32 rules, 256 host names, 128 ranges, and 32 ports per rule: a policy redu refuses is 400 validation_error with its reason. A dict as the API takes it works too:
egress={"default_action": "deny", "rules": [{"action": "allow", "hosts": ["pypi.org"]}]}. Every sandbox shows
egress: one made without rules reads default_action "allow", no rules, and updated_at None. A fork keeps its
original's rules.
change_egress replaces the rules of a running or paused sandbox, live: the same policy, rules and limits as at
create. Nothing restarts; the open connections the new rules refuse are closed. EgressPolicy("allow") removes every
rule.
changed = redu.sandboxes.change_egress(locked.id, EgressPolicy("deny", [
EgressRule("allow", hosts=["pypi.org", "files.pythonhosted.org"], ports=[443]),
]))
print(changed.egress, changed.connections_closed) # every read shows these rules from now onA 202 is waited on through GET /v1/sandboxes/requests/sandbox-egress-rules-{id}, unless wait=False. Sending the
same rules again is safe; the client never sends them twice by itself.
| Code | What it means |
|---|---|
409 egress_change_busy |
a change of its rules is under way: wait for it, then send yours again |
409 egress_change_unavailable |
a running sandbox's rules cannot be changed on this platform yet: create a sandbox with the rules you need |
409 egress_change_unsupported |
it started before its rules could be changed while it runs: it keeps them until it ends |
409 egress_not_filtered |
its connections are not filtered, so rules would never apply to it |
409 sandbox_suspended |
resume it first |
409 sandbox_changing |
another change of it (a resize, a suspend or a resume) is under way: try again in a moment |
409 sandbox_ending, 409 sandbox_not_running |
it is being deleted or has ended, or it does not run |
400 egress_rules_refused |
the rules were refused as written |
502 egress_change_outcome_unknown |
EgressChangeOutcomeUnknownError: the change may have been made; send the same rules again. Until then reads show the rules last confirmed |
Nothing changed in any of them but the last.
max_spend is a cap in GBP for one sandbox (at least 0.10, at most 1000). When what the sandbox has cost reaches it,
the sandbox is deleted, and nothing is charged above it. It can keep running past its cap for up to one usage interval
of the sandbox service plus a minute before it is deleted; that run is not charged. A sandbox made with one shows
spend (so far), max_spend and spend_updated_at. max_spend needs the redu API version that adds sandbox spend
caps: an API without it refuses the field (400 validation_error). A key whose monthly sandbox cap is reached gets
402 spend_cap_reached on create.
With the same API version, each template from templates() has a price (SandboxPrice: GBP per busy vCPU-hour and
per GB-hour of memory while it runs, the disk included, and what an hour costs idle and fully busy). A paused or
suspended sandbox costs storage only: its memory at the storage rate. From the later API version of 21 Nov 2026 the
price also has storage_per_gb_month (the storage rate), paused_or_suspended_per_hour and
paused_or_suspended_per_month, and each snapshot has its own price (SnapshotPrice: per_gb_month, and
per_month, a month of it at its size, None while its size is not known).
r = redu.sandboxes.exec(
sandbox.id,
argv=["node", "-e", "console.log(1 + 1)"], # or a command line: exec(sandbox.id, "echo hi")
env={"A": "1"}, cwd="/root", stdin="...",
timeout_ms=30000, # 1000 to 30000
)
print(r.exit_code, r.signal, r.stdout, r.stderr, r.stdout_truncated, r.stderr_truncated, r.duration_ms)
print(r.idempotency_key, r.attempts)duration_ms is a float: it can carry a fraction.
A command runs for at most 30 seconds. Start longer work in the background and read its output later with another
command (nohup sh -c '...' > /tmp/out.log 2>&1 &, then tail -c 65536 /tmp/out.log). stdout and stderr are cut at
64 KiB each.
A command is not safe to run twice, so every call carries an Idempotency-Key (yours, or a new random one), and the
answers decide what happens next:
| Answer | Did it run? | What the client does |
|---|---|---|
| 200 | yes | returns the result |
| 202 (no result after about 40 s) | may have | sends it again with the same key, which never runs it twice and answers from the first run |
| no answer (lost connection, timeout, a proxy's error page) | may have | the same: sends it again with the same key |
a 2xx whose body is not JSON (unexpected_answer) |
may have | the same; on the last attempt it raises with ran == "unknown" |
502 exec_outcome_unknown |
may have | sends it once more with the same key; a second one is final (ran == "unknown") |
502 exec_result_lost |
yes | raises (ran == "yes"): check its effects before running it again |
503 exec_not_started, 429 sandbox_busy |
no | the key keeps this answer for about a day, so with its own key the client tries once more under a new key; with your key it raises (ran == "no") |
409 idempotency_key_reused |
no | raises: the same key was used for another command |
| any other error | no, or unknown after an earlier lost answer | raises |
At most max_attempts requests (default 4) are sent per call. Every exec error carries ran and idempotency_key, so
you know whether running it again is safe and under which key it was tried. To repeat a command after
ran == "unknown", call exec again with the same input and that key:
from redu_sandbox import ReduError
try:
redu.sandboxes.exec(sandbox.id, "echo hi")
except ReduError as e:
if e.ran == "unknown" and e.idempotency_key:
redu.sandboxes.exec(sandbox.id, "echo hi", idempotency_key=e.idempotency_key)
else:
raiseA sandbox made with public=True can have one public https name per port. The program must listen on
0.0.0.0:<port> and keep running after the command that starts it.
redu.sandboxes.exec(
sandbox.id,
"nohup node -e \"require('http').createServer((q, s) => s.end('ok')).listen(8000, '0.0.0.0')\" > /tmp/http.log 2>&1 &",
)
name = redu.sandboxes.add_public_name(sandbox.id, 8000)
print(name.url) # https://...redu.cloud
redu.sandboxes.remove_public_name(sandbox.id, name.id)Without domain a name is generated under redu.cloud; a domain of your own must be verified for your account first.
open_terminal gives a root shell in the sandbox. Where the platform offers terminals over its websocket, any live
sandbox gets one, private ones included; elsewhere a sandbox made with public=True gets the web terminal.
from redu_sandbox import TerminalSession
terminal = redu.sandboxes.open_terminal(sandbox.id, cols=120, rows=40)
if isinstance(terminal, TerminalSession):
print(terminal.url, terminal.protocol) # open within 60 seconds, once, with a websocket client of your own
else:
print(terminal.url, terminal.username, terminal.password) # the web terminal
closed = redu.sandboxes.close_terminal(sandbox.id)
print(closed.terminal, closed.platform_terminals) # "stopped", "none" or "not_stopped"; "ended" or "not_closed"A websocket terminal (TerminalSession, kind "websocket") carries a one-time token, good for 60 seconds and one
session: open url offering subprotocols (or with the token as a bearer token); binary messages are the terminal's
input and output. idle_timeout_s (60 to 3600) is how long it may sit with no byte either way. When redu answers 202
(a suspended sandbox is woken first) it keeps no token for later, so the client opens it again, up to 3 requests in all
(SESSION_OPEN_ATTEMPTS, then StillPendingError); wait=False hands the 202 back as a PendingRequest. The token
(and the subprotocols, which carry it) is left out of repr(), and the client never puts it in an error.
close_terminal ends these too (platform_terminals "ended", how many in platform_terminals_ended), where the
platform can.
The web terminal (Terminal, kind "web") is a root shell in the browser, behind a username and a password. The
password is answered once and redu keeps it nowhere. Anyone with the url and the password has the shell. To get a new
password, open the terminal again: the old one stops working and the url stays. When redu answers 202, the password
comes with that 202 and the url with the request's end; the client joins the two. With wait=False you get a
PendingTerminal that holds the password, and wait_for_request gives the url later. The password is left out of
repr(), so it does not end up in a log by accident. close_terminal says what it found: only "stopped" says a
running terminal was stopped; "not_stopped" means it may run again with its old password once the sandbox runs
(close it again then, or delete the sandbox).
A sandbox is deleted by itself at its expires_at, timeout_s seconds after its create, unless it is extended. A
timeout_s is 60 up to your account's longest life, limits().max_lifetime_s (2592000, 30 days, for an account with no
card; at most 31536000, 365 days). redu checks it, not this client. While limits().no_end is False, a sandbox lives at
most max_lifetime_s after its create, extends included. The free sandbox lives at most 30 days after its create,
whatever the account (see "The free sandbox").
x = redu.sandboxes.extend(sandbox.id, 7200) # seconds from now
print(x.expires_at, x.previous_expires_at, x.extended, x.capped, x.max_expires_at)The sandbox then ends timeout_s seconds from now, never sooner than it already would (extended is False then), and,
where a longest life holds, at most that long after it was created (capped is True when that cut the ask): the
platform's (max_expires_at, None where it has none), and 30 days for an account with no card and for the free sandbox.
Calling it again is safe, so it works as a keep-alive; send no idempotency_key for that, since a repeated key
replays the first answer and extends nothing. A sandbox costs while it lives. 409 sandbox_deleting,
402 max_spend_reached or spend_cap_reached, and 404 sandbox_not_found once it has ended.
timeout_s=0, at a create or an extend, asks for a sandbox with no end: it runs until you delete it, or until its
max_spend, its API key's monthly cap or a suspended account ends it, and it is billed by use as any sandbox. It reads
expires_at None and max_expires_at None, which never means it has ended. It is for an account with a card, where
limits().no_end is True, never for a sandbox with volumes, and never for the free sandbox. A fork and a lifecycle
change never take 0: extend the sandbox for that.
if redu.sandboxes.limits().no_end:
kept = redu.sandboxes.create("ubuntu-node", timeout_s=0)
print("no end", kept.expires_at, kept.max_expires_at) # None None
redu.sandboxes.delete(kept.id) # it runs until it is deleted| Code | What it means |
|---|---|
403 no_end_needs_card |
the account has no card: give timeout_s in seconds, or add a payment method |
403 free_sandbox_options |
the free sandbox never has no end (see "The free sandbox") |
503 no_end_unavailable |
no end cannot be given right now: nothing was made or changed. Try again in a few minutes, or give timeout_s in seconds and extend it later |
400 validation_error |
on timeout_s, with the reason: no end is not offered, the sandbox has volumes, or the ask is above your longest life (the free sandbox's: 30 days) |
The client sends timeout_s as you give it and leaves these checks to redu. Every code here and under "The free
sandbox" is in SANDBOX_ANSWER_CODES, redu's own answers: a 503 no_end_unavailable is raised at once, never waited on
or sent again as a lost answer.
The platform's maintenance (an update or a planned restart of the server a sandbox runs on) pauses a sandbox with no end
for a few minutes and brings it back as it was; open connections, terminals and SSH sessions are cut. A sandbox lives
on one server with its memory and disk, so a hardware failure there can still end it: the platform then deletes it, and
it ends as lost (see "Limits and ended sandboxes").
redu.sandboxes.pause(sandbox.id) # CPUs stop, memory kept: billed for memory, never CPU; no commands
redu.sandboxes.suspend(sandbox.id) # memory and disk saved, memory freed: no memory charge
r = redu.sandboxes.resume(sandbox.id)
print(r.status, r.from_) # running diskEach returns a SandboxStateResult: status, already (it was in that state), from_ ("disk" after a suspend; the
API's field from) and expires_at. A paused sandbox refuses commands (409 sandbox_not_running); a suspended one is
resumed by its next command (its ExecResult.resumed is True). Both are still deleted at expires_at and still count
against your limits. A 202 is waited on. Codes: 409 sandbox_suspended (a suspended sandbox cannot be paused),
409 sandbox_cannot_suspend (a command or file transfer runs in it, or it was just created: try again in a minute, or
pause it), 409 sandbox_resume_unavailable (no room right now: it stays suspended with its memory and files),
409 sandbox_state_busy (another change of it is under way). No Idempotency-Key is ever sent with these: redu's
replay cache keys on the credential and the key, whatever the route, so a reused key would replay a pause's answer for
a resume.
redu.sandboxes.write_file(sandbox.id, "/root/app/main.py", "print('hi')\n", mode="644")
data = redu.sandboxes.read_file(sandbox.id, "/root/app/main.py") # at most 8 MiB
whole = redu.sandboxes.read_large_file(sandbox.id, "/root/app/main.py") # any size, in 8 MiB ranges
for part in redu.sandboxes.iter_file_ranges(sandbox.id, "/root/app/main.py"):
print(part.offset, len(part.data), part.size)Paths are absolute (at most 4096 characters). read_file raises 413 file_too_large for a file over 8 MiB (its
message says the size): read it with read_large_file, or part by part with iter_file_ranges or
read_file_range(id, path, offset, length), which follows the Content-Range of each answer. 416 range_not_satisfiable past the end, 404 file_not_found when the sandbox has no such file. write_file takes bytes or
a str (written as UTF-8) of at most 12517376 bytes (12 MiB less 64 KiB; a larger one is refused with ValueError before
anything is sent), replaces a file that is there, and creates missing parent folders.
cmd = redu.sandboxes.start_command(sandbox.id, "npm run build", cwd="/root/app")
for out in redu.sandboxes.follow_command(sandbox.id, cmd.id):
print(out.stdout, end="")
end = redu.sandboxes.wait_for_command(sandbox.id, cmd.id) # or all of it at the end
print(end.command.exit_code, end.stdout, end.stdout_lost)
redu.sandboxes.stop_command(sandbox.id, cmd.id, "KILL") # TERM by defaultA background command runs for up to an hour (timeout_ms, default and most 3600000), at most 16 at once per sandbox
(429 sandbox_busy). start_command follows exec's rules for a lost answer and its Idempotency-Key (the table
above): the same key never starts it twice, and its errors carry ran and idempotency_key.
get_command(id, command_id, stdout_offset=, stderr_offset=, wait_ms=) reads the output past the offsets, waiting up to
wait_ms (20000 at most) for more; ask again from stdout_next and stderr_next. follow_command does that until the
command has ended and all its output is read (timeout, in seconds, stops following with WaitTimeoutError; the
command runs on). The sandbox keeps the last 1 MiB of each stream: what was written faster than it was read is counted
in stdout_lost and stderr_lost. 404 command_not_found once it is forgotten (the last 32 ended ones are kept).
snap = redu.sandboxes.take_snapshot(sandbox.id, "before-upgrade")
print(snap.id, snap.status, snap.size_bytes)
for item in redu.sandboxes.list_snapshots(): # oldest first: creating, available, deleting or error
print(item.id, item.name, item.status)
again = redu.sandboxes.create(snapshot=snap.id, name="from-snap", timeout_s=600)
print(again.from_snapshot == snap.id) # True: it started with the snapshot's files, memory and programs
redu.sandboxes.delete_snapshot(snap.id) # sandboxes made from it keep runningA snapshot holds a running or paused sandbox's files, memory and running programs. The sandbox pauses for about a
second while it is written. It is kept until you delete it, also after the sandbox is gone, on the server the sandbox
ran on: it is not a backup. It costs storage by its size from when it is taken until it is deleted (its price). One
take per sandbox at a time (409 snapshot_in_progress). A 202 is waited on, as for a create, and the client never
sends a take twice by itself. A sandbox with volumes cannot be snapshotted (409 sandbox_has_volumes). A create from a snapshot starts at the snapshot's size and
is recorded with its template: 404 snapshot_not_found, 409 snapshot_unavailable (still being taken, being deleted,
or failed), 503 snapshot_server_unavailable (the server that keeps it cannot start it now: nothing was made).
| Code | What it means |
|---|---|
409 sandbox_busy_for_snapshot |
a command or a file transfer runs in it: take it between commands; nothing was taken |
409 snapshot_not_possible |
it is not running or paused: resume a suspended one first |
409 snapshot_limit_reached |
your account holds the most snapshots it can: delete one |
503 snapshot_not_taken |
SnapshotNotTakenError: nothing was kept, safe to take again |
503 snapshot_outcome_unknown |
SnapshotOutcomeUnknownError: the answer was lost and the snapshot MAY have been taken: if it was, it is never listed (list_snapshots() cannot show it), yet it counts against your snapshot limit. Wait a few minutes before you take another; if snapshot_limit_reached answers while fewer snapshots are listed, write to support@redu.cloud |
409 snapshot_deleting |
on delete: it is still being taken, or another delete holds it; try again in a minute |
from redu_sandbox import SnapshotOutcomeUnknownError
try:
nightly = redu.sandboxes.take_snapshot(sandbox.id, "nightly")
except SnapshotOutcomeUnknownError as e:
# it may have been taken, and then it is never listed, yet counts against your snapshot limit:
# wait a few minutes before you take another (e.hint says what to do if the limit is reached)
print(e.hint)
raiseA take whose answer never came (NetworkError) or that you stopped waiting for (WaitTimeoutError) may also have
taken the snapshot: list first (a take that ends snapshot_outcome_unknown is the exception: it is never listed).
copy = redu.sandboxes.fork(sandbox.id, name="try-b", timeout_s=1800, env={"MODE": "b"}, max_spend=1)
print(copy.id, copy.forked_from) # a new sandbox; forked_from is the originalA fork is a new sandbox that is a running copy of a running or paused one as it is now: its files, memory and running
programs, at its template and size. The original goes on. The copy has its own lifetime (timeout_s, 60 up to
limits().max_lifetime_s, default 3600; never 0: extend the copy for no end), its own max_spend and only the env
given here; it keeps the original's egress rules, and is public when the original is (with no names yet). Programs keep
running in the copy, so anything they do outside happens twice. A 202 is waited on; the client never sends a fork twice
by itself (a second one makes a second copy). 409 fork_not_now (a command or a file transfer runs in it),
409 fork_unsupported, 409 sandbox_not_running, 503 fork_no_room (its server is full: try again in a few minutes).
page = redu.sandboxes.egress_log(sandbox.id, since=0, limit=200)
print(len(page.events), page.next_since, page.more)
for e in redu.sandboxes.iter_egress_events(sandbox.id):
if e.type == "connect":
print(e.seq, e.host or e.address, e.port)
elif e.type == "denied":
print(e.seq, "denied by rule", e.rule)The log lists each outbound connection (connect: host, address, port, protocol), a rule's denial (denied,
with the rule's number, 1 for the first, or "default"), its end (closed, with bytes_out, bytes_in and
duration_ms), a failure (failed), and connections refused before any rule (refused: reason too_many_open,
too_fast or local_address, with counts). since is the log's own counter (0 for its start); ask again from
next_since while more is True. A page can be empty with more True: the log also holds records that are not
connections, which are never shown. iter_egress_events does that for you and ends at the log's end as it is now. It
never asks twice from the same place: a page whose next_since does not move ends it. To read on later, pass the last
event's seq as since.
r = redu.sandboxes.resize(sandbox.id, vcpus=2, memory_mb=2048)
print("resized", r.resized_from, r.resized_to, r.price.busy_per_hour if r.price else None)A running sandbox's vCPUs (1 to 4) and memory (1024 to 8192 MB) change live: nothing restarts, and its files and
programs stay. Memory moves in 2 MB steps within the range its template allows. The answer is the sandbox at its new
size, with resized_from and resized_to (the API's resize.from and resize.to) and its price at that size; it
is billed at the new size from then on. A 202 is waited on through GET /v1/sandboxes/requests/sandbox-resize-{id},
unless wait=False. The size is a target, not a step, so calling it again for the same size is safe; the client never
sends it twice by itself. 409 resize_not_available (its template cannot be resized), 409 resize_busy (one is under
way), 409 resize_refused (no room right now: try again in a minute), 409 sandbox_not_running (resume it first),
400 resize_out_of_range, 429 resize_limit_reached, and three 502s with a class of their own: ResizeFailedError
(nothing changed), ResizeIncompleteError and ResizeOutcomeUnknownError (get() shows the size it has, which is
what it is billed at). The free sandbox keeps its size: 403 free_sandbox_size (a paid sandbox, or a paid fork of it,
can be any size).
A sandbox's own range is in its resize_range when the platform reports one: a SandboxResizeRange(min_vcpus, max_vcpus, min_memory_mb, max_memory_mb, memory_step_mb), set by the size it was created at and fixed while it lives.
Ask inside it (memory from min_memory_mb in steps of memory_step_mb), or it is 400 resize_out_of_range. Without
one (None), the bounds above apply. resize_range is also None when the platform answers it as null, which means the
sandbox cannot be resized: "resize_range" in sandbox.raw tells the two apart.
from redu_sandbox import verify_audit_chain
page = redu.sandboxes.audit_log(sandbox.id, since=0, limit=200)
check = verify_audit_chain(page.events)
print("chain", check.ok, check.checked, check.problem)
events = list(redu.sandboxes.iter_audit_events(sandbox.id))
print("whole log", len(events), verify_audit_chain(events).ok)The sandbox's own event log, oldest first: each command and file read or write sent to it through the API, its
outbound connections, the programs started and ended inside it, the rule decisions that refuse something, and the
machine's own life. Never a command's env, its output or a file's content. Each AuditEvent keeps the record as the
sandbox service wrote it, unchanged, in .raw (seq, t_ns, mono_ns, sandbox_id, source, kind, trust,
data, prev, h), with the same fields as attributes. A record redu cannot answer whole comes in its place with
withheld set (platform_detail, too_large or not_json), its seq, prev, h, at and bytes. trust "guest" records come from inside the sandbox, so a program with root there can stop or forge them.
kind= takes a kind or a family of kinds (exec, exec.request, file, egress, proc, rule, vm), or a list
of up to 10. iter_audit_events follows next_since to the log's end as it is now and never asks twice from the same
place. A read changes nothing, so a 202, a lost answer or a 429 too_many_log_reads (at most 2 log reads of your
account at once; TooManyLogReadsError once the retries are spent) is read again, the 429 after its Retry-After.
502 event_log_unreadable (EventLogUnreadableError): the log cannot be read past that since.
verify_audit_chain checks the records as the API describes: seq counts 1, 2, 3 without gaps; prev is the h
before it (64 zeros for seq 1); h is the SHA-256 of the record without h, written as
json.dumps(record, sort_keys=True, separators=(",", ":")) writes it, which is the very call the sandbox service
hashes with. It stops at the first problem (not_a_record, seq_gap, prev_mismatch or hash_mismatch). A
withheld record's own h cannot be checked, but the order across it is. Check from since=0, or pass
after=check.last (from the check of the page before) to go on from a later page. For records read with kind, pass
chain=False: only each record's own h can be checked. The chain has no key or signature: it shows a record changed
or removed in the middle, not a log cut at its end or replaced as a whole.
What puts a sandbox to sleep and what ends it, in one place: its idle pause, its end, and its spend against its cap.
lc = redu.sandboxes.get_lifecycle(sandbox.id)
print(lc.idle_pause_s, lc.expires_at, lc.max_expires_at, lc.spend, lc.max_spend)
after = redu.sandboxes.set_lifecycle(sandbox.id, idle_pause_s=300, max_spend=5, timeout_s=7200)
print("lifecycle", after.changed.idle_pause_s, after.changed.max_spend) # each part only when it changed itidle_pause_s (0 to 86400 seconds; 0 never pauses it) also goes in a create or a fork (a fork without it keeps the
original's): the sandbox is paused after that long without activity, billed for its memory only, and resumes on its
next command. In set_lifecycle a field left out stays as it is: timeout_s works as extend does (never 0),
max_spend must be above what it has cost so far (409 max_spend_below_spend), and max_spend=None removes the cap
(leaving it out keeps it); the free sandbox costs nothing, so it takes neither (403 free_sandbox_options). One change
of a sandbox's lifecycle runs at a time (409 lifecycle_busy). A 202 is waited on through
GET /v1/sandboxes/requests/sandbox-lifecycle-{id}, unless wait=False. A change that failed after its idle pause or
its cap was applied says so in the error's details["applied"]; sending the same change again is safe. 502 idle_pause_outcome_unknown is IdlePauseOutcomeUnknownError; 503 usage_not_current means try again in a few minutes.
limits = redu.sandboxes.limits()
print(limits.available.vcpus, limits.used.sandboxes, limits.snapshots.limit)
page = redu.sandboxes.list_ended(limit=20)
while True:
for ended in page.sandboxes:
print(ended.id, ended.ended_at, ended.end_reason, ended.spend)
if page.next_cursor is None:
break
page = redu.sandboxes.list_ended(limit=20, cursor=page.next_cursor)limits holds limits, used and available (each sandboxes, vcpus, memory_mb, disk_gb), by_status, snapshots,
and redu's own words on what counts (counted) and how to have them raised (raise_, the API's raise).
max_lifetime_s and no_end say how long your sandboxes may live (see "Lifetime"), and free_sandbox (a
FreeSandbox) shows your free sandbox (see "The free sandbox"); each is None when redu does not answer it. A
FreeSandbox has available (when False, reason says why: a FreeSandboxReason with code, message and hint),
size (a SandboxSize), hours_per_month, hours_used, hours_left, month, resets_at, sandbox_id (the live
one, or None), counted, at_limit and max_lifetime_s (its own longest life, 30 days), each None when redu does not
say it.
Ended sandboxes are the ones that ended in the last 7 days, newest end first, from redu's own record: end_reason is
deleted, expired, max_spend, key_spend_cap, lost for a sandbox with no end that a hardware failure ended (the
platform deleted it), or None (SandboxEndReason; a reason a later API adds comes as its str). limit is 1 to 100
(ENDED_PAGE_MAX_LIMIT, 50 by default). get_ended(id) reads one (404 sandbox_not_found otherwise, also for a live
one).
An account with the free tier has one free sandbox: 1 vCPU and 1 GB of memory from a template, never charged, one at a
time, with 50 hours a calendar month (UTC) of running and paused time (suspended time does not count). An account with
no card has it during its 7-day trial; an account with a card has it every month, beside its paid sandboxes. When the
month's hours are used it is deleted, and a new one can be made from the 1st of the next month. It never has no end, and
it lives at most 30 days after its create, extends included, whatever the account
(limits().free_sandbox.max_lifetime_s). create(template, free=True) asks for it, free=False for a paid sandbox;
left out, nothing is sent, and an account with no card gets its free sandbox while any other gets a paid one. It takes
no snapshot, other size, disk_gb, public, network_id, volumes, max_spend or timeout_s=0, and it is created
through the redu MCP only: a create from this client that asks for it (free=True, or an account with no card leaving
free out) answers 403 free_sandbox_mcp_only once nothing else refuses it.
Once made it is used as any sandbox, and its reads carry raw["free"] True. It keeps its size (a resize answers
403 free_sandbox_size) and takes no max_spend (403 free_sandbox_options); an extend of it with 0 answers
403 free_sandbox_options, and an extend or a lifecycle change past its 30 days a 400 validation_error on
timeout_s. limits().free_sandbox says whether your account can have it now (available, and reason when not), its
hours used and left this month, and when they reset:
free = redu.sandboxes.limits().free_sandbox # None from an API without it
if free is not None:
print("free sandbox", free.available, free.hours_used, free.hours_left, free.resets_at)
print("hours a month", free.hours_per_month, "longest life", free.max_lifetime_s) # 50 and 2592000 (30 days)| Code | What it means |
|---|---|
403 free_sandbox_mcp_only |
it is created through the redu MCP only |
403 free_sandbox_options |
the create asked for something it does not take; or timeout_s=0 at an extend of it, or a max_spend in a lifecycle change of it |
403 free_sandbox_exists |
the account has its free sandbox already: use it, or delete it to make another |
409 free_sandbox_creating |
the account's free sandbox is being created |
402 free_sandbox_hours_used |
its hours for this month are used: a new one can be made from the 1st (UTC) |
403 free_sandbox_size |
a resize of it: it keeps its size |
403 free_sandbox_unavailable |
the account has no free sandbox: its setup is not complete |
These seven and the two of "Lifetime" (no_end_needs_card, no_end_unavailable) are in SANDBOX_ANSWER_CODES.
import time
build = redu.sandboxes.build_template("my-python", "python:3.12", memory_mb=2048)
while True:
build = redu.sandboxes.get_template_build(build.id) # as it is now, with its log
if build.status in ("done", "failed"):
break
time.sleep(15)
if build.template_id:
mine = redu.sandboxes.create(build.template_id)
print("built", mine.template)
redu.sandboxes.delete(mine.id)
redu.sandboxes.delete_template(build.template_id)A build is accepted (queued) and then goes on by itself, through pulling, unpacking, building, uploading and
registering, to done (with its template_id) or failed (with its error). One build runs at a time per account
(409 template_build_in_progress), so the client never repeats one by itself. registry_auth=RegistryAuth(username, password) (or a dict) is for a private image: it is used for that one build, kept nowhere, left out of repr() and
never echoed by this client. A built template is billed as stored data, as a snapshot is, from when its build is done
until delete_template deletes it (409 template_in_use while snapshots need it: the error's details["snapshots"]
names them). cancel_template_build(build.id) cancels a running build (cancelling, or finishing once it is
registering) and forgets one that ended (forgotten); pending means cancel it again in a moment. 429 template_build_rate_limited (your builds of the last 24 hours) is never sent again by the client.
import os
from redu_sandbox import SecretInput
with_key = redu.sandboxes.create(
"ubuntu-node",
secrets=[SecretInput("OPENAI_API_KEY", os.environ["OPENAI_API_KEY"], ["api.openai.com"])],
)
print(with_key.secrets) # [SecretView(name='OPENAI_API_KEY', hosts=['api.openai.com'])]: never a value
redu.sandboxes.set_secrets(with_key.id, []) # replaces them all, values included; [] removes them
redu.sandboxes.remove_secrets(with_key.id)A secret is bound to hosts: the sandbox sees a placeholder in its env variable, and the platform puts the real value
into requests to those hosts only, so code in the sandbox never reads it. Up to 16, each a SecretInput(name, value, hosts) or a dict as the API takes it; a name may not also be in env. Answers name each secret and its hosts, never its
value, and this client never echoes one, in an answer, an error or repr(). A value is never shown back: it lives in the
sandbox's own memory, and to keep the sandbox through the platform's maintenance (an update or a planned restart) it is
written into the sandbox's saved state on the server it runs on, readable by the platform only, and removed when the
sandbox is brought back. One change at a time (409 secrets_change_busy); 502 secrets_outcome_unknown (SecretsOutcomeUnknownError): send the same list again.
ssh = redu.sandboxes.add_ssh_key(sandbox.id, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl me@laptop")
print(ssh.server, ssh.known_hosts) # and ssh.connect.ssh_config, for ~/.ssh/config
once = redu.sandboxes.open_ssh(sandbox.id)
print("ssh session", once.url) # once.ssh is a ready command for one connection, within 60 seconds
redu.sandboxes.remove_ssh_key(sandbox.id, ssh.keys[0].fingerprint)
redu.sandboxes.remove_all_ssh_keys(sandbox.id)SSH reaches any live sandbox of yours through the platform, private ones included, when its template has an SSH server
(409 ssh_unsupported otherwise; 409 ssh_unavailable where the platform has no SSH). Adding or removing a key needs
an API key with sandbox:ssh; open_ssh needs sandbox:ssh_connect. open_ssh answers a one-time token (left out of
repr(), never put in an error), opened again on a 202 as a websocket terminal is. remove_all_ssh_keys also stops the
SSH server and ends the sessions open through the platform. 502 ssh_outcome_unknown is SshOutcomeUnknownError.
Every refusal or failure is a ReduError (also exported as RedusError, the TypeScript SDK's name):
from redu_sandbox import NotFoundError, ReduError
sandbox_id = "00000000-0000-4000-8000-000000000000"
try:
redu.sandboxes.get(sandbox_id)
except ReduError as e:
if e.code == "sandbox_not_found":
print(e.status, e.message, e.hint) # 404, and redu's own sentences
else:
raise
try:
redu.sandboxes.get(sandbox_id)
except NotFoundError as e: # the same error, caught by its class
print(e.code)| Field | Meaning |
|---|---|
status |
the HTTP status, or 0 when no answer came back |
code |
redu's stable code (quota_exceeded, sandbox_not_public, ...), or one of the client's own: network_error, wait_timeout, still_pending, unexpected_answer |
message, hint |
redu's sentences, unchanged |
details |
the rest of redu's error (a validation error's issues, a scope error's required_scope) |
retry_after_s |
from Retry-After |
workflow_id |
when the error is how a request ended after its 202 (a create, a delete, a name's or a terminal's change, an extend, a pause, suspend or resume, a fork, a snapshot's take or delete, a resize, a change of egress rules, a lifecycle change, a change of secrets or SSH keys, a template build's start or a template's delete) |
ran, idempotency_key |
on exec and start_command errors (see the table above) |
The class says what kind of answer it was: NetworkError, WaitTimeoutError, StillPendingError,
UnexpectedAnswerError (the client's own codes), then by status BadRequestError (400, 422), AuthenticationError
(401), PaymentRequiredError (402), PermissionDeniedError (403), NotFoundError (404), ConflictError (409),
RateLimitError (429) and ServerError (5xx). Some of redu's codes have a class of their own, so that an except
tells apart answers of one status: SnapshotOutcomeUnknownError (a snapshot that may exist) and
SnapshotNotTakenError (nothing was kept), both 503s; ResizeFailedError, ResizeIncompleteError,
ResizeOutcomeUnknownError, EventLogUnreadableError, EgressChangeOutcomeUnknownError, VolumeAttachFailedError,
IdlePauseOutcomeUnknownError, SecretsOutcomeUnknownError and SshOutcomeUnknownError, 502s; and
TooManyLogReadsError, a RateLimitError. e.to_dict() gives the fields a log needs.
A 429 rate_limited is sent again by the client after its Retry-After (up to max_rate_limit_retries, default 2):
redu's rate limits answer before any route runs, so nothing was done.
import httpx
from redu_sandbox import Redu
client = Redu(
api_key="...", # or token=...; default REDU_API_KEY
base_url="https://console.redu.cloud",
timeout=120, # seconds per HTTP request; redu holds a sandbox request up to about 40 s
poll_interval=5, # seconds between reads of a request that answered 202
max_rate_limit_retries=2,
user_agent="my-agent/1.0",
http_client=httpx.Client(), # optional: your own (proxies, certificates); you close it
)
client.close() # or use `with Redu(...) as client:`redu holds a read of a request that answered 202 for up to 10 s while it runs, so such a read is never cut before 60 s
(REQUEST_READ_MIN_TIMEOUT_S), whatever timeout says, and the time it took counts toward poll_interval: the next
read follows a held read at once.
import asyncio
from redu_sandbox import AsyncRedu
async def main() -> None:
async with AsyncRedu() as redu:
sandbox = await redu.sandboxes.create("ubuntu-node")
try:
result = await redu.sandboxes.exec(sandbox.id, "uname -a")
print(result.stdout)
finally:
await redu.sandboxes.delete(sandbox.id)
asyncio.run(main())python3 -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/python -m pytest
.venv/bin/mypy # strict, over src/redu_sandbox and testsGitHub Actions runs the same two, the tests and mypy, on every push and pull request (.github/workflows/test.yml,
Python 3.12).
The unit tests run against tests/fake_redu.py, a fake redu that answers as the redu API's sandbox routes do. When
those routes change, change the fake with them. Every test runs on the sync and on the async client.
tests/fixtures/audit-chain.json holds audit records hashed by Python exactly as the sandbox service hashes them (the
same file is in every redu sandbox SDK). tests/test_readme.py runs every Python block of this README, in order,
against the fake served on a local port, so an example that stops working fails the tests.
python -m build makes the sdist and the wheel in dist/; twine check dist/* checks them.
Apache License 2.0 (Apache-2.0): see the LICENSE file. Copyright 2026 REDU CLOUD LTD.