Skip to main content

solari-sandbox (Python)

Python SDK for Solari Sandboxes — fast, ephemeral code sandboxes (micro-VMs) with a code interpreter, filesystem, ports, and git. Mirrors the TypeScript @solarisdk/sandbox package.

Capabilities and limits at a glance: https://docs.getsolari.com/sdk-capabilities.

Install

pip install solari-sandbox

Quickstart

import asyncio, os
from solari_sandbox import SandboxClient

async def main():
    client = SandboxClient(api_key=os.environ["SOLARI_API_KEY"])
    sb = await client.create(template="base")
    try:
        await sb.connect()
        result = await sb.run_code("print(6 * 7)")
        print("".join(r.text or "" for r in result.results if r.type == "stdout"))   # -> 42
    finally:
        await sb.kill()
        await client.aclose()

asyncio.run(main())

SandboxClient(...) accepts api_key, base_url (default https://api.getsolari.com; pass https://api-sta.getsolari.com for staging), and call_timeout_ms. The same slr_live_… key authenticates against both the browser and desktop/sandbox APIs. run_code returns a RunCodeResult: its results list holds items of type "stdout", "stderr" or "result" (plus charts and error).

Releasing sandboxes

A sandbox keeps running (and billing) until its idle timeout unless you release it. kill() does that; async with (or with, for the synchronous client) calls it for you on every exit path:

async with await sandboxes.create() as sbx:
    await sbx.commands.run("echo", args=["hi"])
# killed here

A process that ends with a sandbox it never killed or closed prints a one-line reminder at exit. Timeouts are in milliseconds: idle_timeout_ms is the rolling idle window, and commands.run(..., timeout_ms=) the deadline for one command (result.timedOut says it was cut off; the default is 600 000 ms).

Idle policy

One setting says what happens as a sandbox sits idle. Offsets run from the last activity and must increase:

sbx = await sandboxes.create(idle_policy="park@30s,hibernate@2m,pause@5m,delete@1d")
# or: format_idle_policy(park="30s", pause="5m", delete="1d")

park freezes the sandbox (free, wakes in milliseconds), hibernate checkpoints it and frees the slot, pause snapshots it and frees the slot (connect resumes it), and delete destroys it (a paused sandbox is deleted at most 27 days after the pause). A policy with park or hibernate and nothing after gets a pause added 24 hours later; the sandbox view's idlePolicy shows what was applied. Do not combine it with idle_timeout_ms or the idle keys of lifecycle (the gateway answers 400); autoResume still applies.

Synchronous use

Not running asyncio? SyncSandboxClient takes the same arguments and hands back synchronous handles: every method runs to completion on the client's own event loop and returns its value (create, connect, start and create_desktop all return such handles).

import os
from solari_sandbox import SyncSandboxClient

with SyncSandboxClient(api_key=os.environ["SOLARI_API_KEY"]) as client:
    sb = client.create(template="base")
    try:
        sb.connect()
        result = sb.run_code("print(6 * 7)")
        print("".join(r.text or "" for r in result.results if r.type == "stdout"))   # -> 42
        print(sb.files.list("/")[0].name, sb.metrics().cpuPct)
    finally:
        sb.kill()

One consequence of sharing one loop: output callbacks such as on_stdout fire while a call is running on the handle (for example inside handle.wait()), not between calls; async with on a sync handle is not supported.

Restarting a stopped sandbox

When the guest powers itself off the sandbox goes to state stopped; the host keeps its disk. start() boots it again (a cold boot: processes and memory are gone, files on disk are kept) and returns a live handle on the fresh control URL:

sb = await client.start(sandbox_id)       # sync client: sb = client.start(sandbox_id) (a sync handle)
await sb.connect()

Calling it on an already-running sandbox is fine. Errors carry .status and .code: 409 NotStopped (a paused sandbox needs resume), 409 StartInProgress (poll get until it is running), 409 StoppedDiskMissing / StoppedDiskUnsafe / GoldenMismatch / DiskPlatformMismatch / DiskShaMismatch / DiskExceedsSpec / DiskOwnerMismatch (the host cannot start this disk), 409 HostCapabilityMissing (the host pool is not armed for start; not retryable), 500 StartFailed (the sandbox stays stopped with its disk, so calling again is safe), 502 StartHostError (host unreachable, retryable), NoCapacityError (503 NoCapacity or StartTimeout, retryable) and ConcurrencyLimitError (429). A stopped sandbox reports state == "stopped" from get; every other route on it answers 409 SandboxStopped (only get and kill still work). start() is not retried automatically. The gateway route is POST /sandboxes/:id/start.

Docs: https://getsolari.com

Metadata

Release files for solari-sandbox 0.6.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for solari-sandbox 0.6.3
File Size Uploaded Provenance Actions
solari_sandbox-0.6.3.tar.gz 17.9 kB Without provenance Details for solari_sandbox-0.6.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for solari-sandbox 0.6.3
File Interpreter ABI Platform Actions
solari_sandbox-0.6.3-py3-none-any.whl Python 3 none any Details for solari_sandbox-0.6.3-py3-none-any.whl

Total release size: 30.2 kB

Release files / solari_sandbox-0.6.3.tar.gz

Download URL solari_sandbox-0.6.3.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b38b250f1501289c64d9950fad76efacd5ff06b9ea060c56b0ffa9c70093bc60
BLAKE2b-256 checksum
How to use checksums
9f4abb9e4df129d32ada4ed88dce79efb5d984923ee307bbeaf58b7d8b19a8fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / solari_sandbox-0.6.3-py3-none-any.whl

Download URL solari_sandbox-0.6.3-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c614fbc358edac66d7087a2ba87f0f6287776cfbdc218f1150821b686c289748
BLAKE2b-256 checksum
How to use checksums
b756ddd9a224800efa9d702fb1b00bec40bc8e682d5e383ec076920a611b5b6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for solari-sandbox 0.6.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page