Queued async code run creation, waiting, and cancellation are not part of the
hosted private beta launch surface. Remote host-agent routing for queued code
runs is not implemented yet, so use sandbox.run_code() or
sandbox.code_interpreter.run_code() for hosted beta workloads.
list_runs() is available for read-only hosted beta inspection. The mutation
snippets below document the queued-run API shape for local/self-hosted control
planes that can route the assigned runtime host. They are not acceptance
criteria for hosted private beta.
Future queued run mutations
ctx = sandbox.code_interpreter.create_code_context(cwd="/workspace")
run = sandbox.code_interpreter.create_run(
"import time\nfor i in range(5): time.sleep(1)\nprint('done')",
context=ctx,
timeout=60,
)
print(run.id, run.status)
Wait or cancel
current = sandbox.code_interpreter.get_run(run.id)
print(current.status)
finished = sandbox.code_interpreter.wait_for_run(run.id, timeout_secs=120)
print(finished.status)
# sandbox.code_interpreter.cancel_run(run.id)
List runs
page = sandbox.code_interpreter.list_runs(status="succeeded", limit=20)
for item in page["items"]:
print(item.id, item.status)
Artifacts
artifacts = sandbox.code_interpreter.list_artifacts(limit=20)
for item in artifacts["items"]:
print(item["id"], item.get("kind"))
artifact = sandbox.code_interpreter.get_artifact("artifact_...")
content = sandbox.code_interpreter.download_artifact(artifact.id)
preview = sandbox.code_interpreter.preview_artifact(artifact.id)
sandbox.code_interpreter.delete_artifact(artifact.id)
list_artifacts() returns paginated raw artifact dictionaries. Use
get_artifact() for a typed CodeArtifact, and use download_artifact() or
preview_artifact() for bytes.