Add Sandbox SDK on a unified httpx client (0.2.0)#19
Open
ats3v wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the Sandboxes feature (deepinfra/backend#3148) and modernizes the package around one unified client.
What changed
SandboxAPI (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.DeepInfraClient, rewritten in place onto httpx (wasrequests, 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).TextGeneration,Embeddings,AutomaticSpeechRecognition,TextToImage) but now run on the unified client;requests/requests-toolbeltdropped.MaxRetriesExceededErroris preserved as a subclass ofAPIConnectionError. Also fixesfrom deepinfra import TextGeneration, which was missing from the exports in 0.1.0.pyproject.toml(0.2.0, py>=3.9, deps httpx+pydantic only),py.typed, minimal CI on the self-hosted runner (python:3.12-slimcontainer: ruff, mypy, pytest), PyPI trusted publishing onv*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/modelsand surfaced a pydantic error; now a clean 404 +ValueErroron empty id), andcreate(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.