Repository navigation
feat: sandbox commands API and per-command cwd/env - #685
Open
zackmckennarunpod wants to merge 1 commit into
Open
zackmckennarunpod wants to merge 1 commit into
zackmckennarunpod wants to merge 1 commit into
Conversation
Adds start_command/get_command on Sandbox and AsyncioSandbox, returning a command handle with refresh, wait, cancel, output (paged snapshot) and logs (SSE stream that keeps the end event and the resume offset). exec accepts cwd and env, refused locally with background as the API refuses them. SandboxInfo reads runtime and egressPolicy. Matches rphttp2 v2.15.0.
This branch has not been deployed
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.
Brings the sandbox SDK in #595 up to the sandbox REST API in rphttp2 v2.15.0. That release added two things the SDK didn't cover:
cwdandenvon exec (runpod/rphttp2#485).POST /v2/sandboxes/{id}/commands,GET/DELETE .../commands/{commandId},GET .../commands/{commandId}/logs(JSON snapshot or SSE). Commands keep their output and can run for up to 24 hours, whereasexec(background=True)returns no output.API
AsyncioSandboxhas the same methods, awaited (AsyncioSandboxCommand,AsyncioCommandLogStream).Behavior notes
start_commandgoes through_ready_operation, so only a 409sandbox_startingis retried. A 409command_limit_reached(8 concurrent commands) raisesSandboxConflictErrorwith thatcode.application/jsonwith the command (statusfailed) is returned as a handle, not raised. A 422application/problem+json(invalid request) still raises.event: endand keeps it onstream.end. Onevent: timeout(after 1 hour) orevent: error, it stops withendunset and keepsnext_offsetanderrorso the caller can resume withlogs(offset=...). It never reconnects on its own, the same as sandbox logs. Unknown named events are skipped.execrefusescwd/envtogether withbackground=Truebefore sending anything. The API returns 422 for that combination.SandboxInfogainsruntimeandegress_policy(raw mappings, defaulted toNone)._sse_events(), which both log streams use. Sandbox log behavior is unchanged, and the existing SSE tests still pass.Testing
pytest tests/test_sandbox.py tests/test_sandbox_contract.py tests/test_sandbox_commands.py tests/test_init.py tests/test_api/test_sandbox_rate_limit.py: 137 passed (25 new, intests/test_sandbox_commands.py). The shared REST peer intests/test_sandbox.pygained the command routes.tests/test_serverless/test_refresh_worker.py::test_process_per_job_refresh_exits_without_taking_next_job. It fails the same way on this PR's base without these changes.v2-rest.runpod.dev,python:3.12-slim):exec(cwd="/tmp", env={"FOO": "bar"})printed/tmpandFOO=bar.cwd="/usr"andenvstreamed 6 lines tagged stdout/stderr, thenend(exited, exit code 0, 279 bytes).waitreturnedexitedandoutput()returned the full text witheof=True.streams="stderr"returned only the stderr line.cancel()onsleep 300returnedcancelled.