Skip to content

Commit 2b8fafd

Browse files
committed
feat(sdk): add sandbox state
1 parent 69e8373 commit 2b8fafd

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

sdks/sandbox/python/src/opensandbox/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
SandboxImageSpec,
4747
SandboxInfo,
4848
SandboxMetrics,
49+
SandboxState,
4950
SandboxStatus,
5051
)
5152

@@ -68,6 +69,7 @@
6869
# Sandbox models
6970
"SandboxInfo",
7071
"SandboxStatus",
72+
"SandboxState",
7173
"SandboxCreateResponse",
7274
"SandboxEndpoint",
7375
"SandboxImageSpec",

sdks/sandbox/python/src/opensandbox/models/sandboxes.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,48 @@ class SandboxMetrics(BaseModel):
255255
)
256256

257257
model_config = ConfigDict(populate_by_name=True)
258+
259+
260+
class SandboxState:
261+
"""High-level lifecycle state of the sandbox.
262+
263+
This class provides constant string values for sandbox states.
264+
Note that the sandbox service may introduce new states in future
265+
versions; clients should handle unknown string values gracefully.
266+
267+
Common States:
268+
PENDING (str): Sandbox is being provisioned.
269+
RUNNING (str): Sandbox is running and ready to accept requests.
270+
PAUSING (str): Sandbox is in the process of pausing.
271+
PAUSED (str): Sandbox has been paused while retaining its state.
272+
STOPPING (str): Sandbox is being terminated.
273+
TERMINATED (str): Sandbox has been successfully terminated.
274+
FAILED (str): Sandbox encountered a critical error.
275+
UNKNOWN (str): State is unknown or unsupported by the current version.
276+
277+
State Transitions:
278+
- Pending -> Running: After creation completes.
279+
- Running -> Pausing: When pause is requested.
280+
- Pausing -> Paused: After pause operation completes.
281+
- Paused -> Running: When resume is requested.
282+
- Running/Paused -> Stopping: When kill is requested or TTL expires.
283+
- Stopping -> Terminated: After kill/timeout operation completes.
284+
- Pending/Running/Paused -> Failed: On critical error.
285+
"""
286+
287+
PENDING = "Pending"
288+
RUNNING = "Running"
289+
PAUSING = "Pausing"
290+
PAUSED = "Paused"
291+
STOPPING = "Stopping"
292+
TERMINATED = "Terminated"
293+
FAILED = "Failed"
294+
UNKNOWN = "Unknown"
295+
296+
@classmethod
297+
def values(cls) -> set[str]:
298+
"""Returns a set of all known state values."""
299+
return {
300+
v for k, v in cls.__dict__.items()
301+
if k.isupper() and not k.startswith("_")
302+
}

0 commit comments

Comments
 (0)