Skip to content

Add Sandbox SDK on a unified httpx client (0.2.0)#19

Open
ats3v wants to merge 3 commits into
mainfrom
sandbox-sdk
Open

Add Sandbox SDK on a unified httpx client (0.2.0)#19
ats3v wants to merge 3 commits into
mainfrom
sandbox-sdk

Conversation

@ats3v

@ats3v ats3v commented Jul 10, 2026

Copy link
Copy Markdown
Member

Adds the Sandboxes feature (deepinfra/backend#3148) and modernizes the package around one unified client.

What changed

  • Sandbox API (sandbox_api.py): create (blocks until running, "10m"-style timeouts), from_id, list(tags=...), exec/run_python (aggregate the NDJSON exec stream), fs.read/fs.write, stop/start/terminate, context managers, and async twins (acreate, aexec, ...) for every network method.
  • One DeepInfraClient, rewritten in place onto httpx (was requests, single-URL, POST-only): sync + async, streaming, pooled connections, typed exceptions parsed from both {"error"} and FastAPI {"detail"} error shapes. Retries: connect-errors where marked, 502/503/504 only on GETs, never on non-idempotent POSTs (the old client retried 4xx ×5).
  • Legacy inference wrappers keep their public API (TextGeneration, Embeddings, AutomaticSpeechRecognition, TextToImage) but now run on the unified client; requests/requests-toolbelt dropped. MaxRetriesExceededError is preserved as a subclass of APIConnectionError. Also fixes from deepinfra import TextGeneration, which was missing from the exports in 0.1.0.
  • Packaging/CI: hatchling pyproject.toml (0.2.0, py>=3.9, deps httpx+pydantic only), py.typed, minimal CI on the self-hosted runner (python:3.12-slim container: ruff, mypy, pytest), PyPI trusted publishing on v* tags with a tag==version guard, README/CHANGELOG/examples.

Not in this PR (designed, lands next)

exec_stream, snapshot/from_snapshot, expose_port, fs.upload_dir — no stubs shipped; each lands behind its backend endpoint. The server side of exec/fs is stubbed in deepinfra/backend#3474; end-to-end verification follows once the implementation PR lands.

Verification

Prod e2e (2026-07-10, real sandboxes against api.deepinfra.com): full deployed lifecycle surface exercised sync + async — create (wait/no-wait), wait_until_running, refresh, list + tag filtering, from_id, stop/start/terminate, both context managers, 3 concurrent acreate, plus break attempts (path-traversal ids, empty id, junk/negative durations, unknown plan, non-string tags, instant wait-timeouts, double-stop): 24/24 passed, no sandboxes leaked. exec/run_python/fs not exercised (server side still stubs).

Break-testing found and fixed two bugs (with regression unit tests): sandbox ids are now URL-quoted in paths (from_id("../models") escaped to /v1/models and surfaced a pydantic error; now a clean 404 + ValueError on empty id), and create(wait=False) now populates fields with one GET instead of returning an empty-state handle.

Unit suite: 98 passed (respx-mocked); mypy strict + ruff clean.

ats3v added 2 commits July 10, 2026 12:15
Self-hosted runners are unsafe on a public repo (fork PRs execute
arbitrary code on the runner). Restore the GitHub-hosted matrix so the
full supported Python range (>=3.9) is actually tested, and advertise
it in the trove classifiers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant