Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Versions follow [Semantic Versioning](https://semver.org/).

### Added

- Optional sandbox expiry through `CreateSandboxRequest.timeout_minutes`, with
`expires_at` response fields and an optional final-minute SIGTERM warning.
- Reusable disk and full snapshot create, get, list, and delete operations,
plus sandbox restoration through `CreateSandboxRequest.snapshot_id`.
- Checkpoint create, list, restore, and delete operations scoped to
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ sandbox.set_labels({"environment": "production"})
List filters use AND semantics. `set_labels()` merges the supplied keys into
the existing label map.

## Limit sandbox lifetime

```python
sandbox = client.create_sandbox(
CreateSandboxRequest(
shape="s-1vcpu-1gb",
rootfs="devbox:1",
timeout_minutes=10,
sigterm_before_expiry=True,
)
)
print(sandbox.data.expires_at)
```

`timeout_minutes` accepts 2–1440 whole minutes and starts when the sandbox first
reaches `running`. Activity and pause/resume do not extend the deadline.
`sigterm_before_expiry` requests a best-effort warning to managed workloads
during the final minute and requires `timeout_minutes`.

## Capture and restore snapshots

```python
Expand Down
6 changes: 6 additions & 0 deletions examples/hello_world/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ def main() -> None:
name="hello-python",
shape="s-4vcpu-4gb",
rootfs="devbox:1",
timeout_minutes=10,
sigterm_before_expiry=True,
)
)
print(
f"expires_at={sandbox.data.expires_at} "
f"sigterm_before_expiry={sandbox.data.sigterm_before_expiry}"
)
try:
response = sandbox.run_command(
RunCommandRequest(command="sh", arguments=["-c", "uname -a"])
Expand Down
2 changes: 2 additions & 0 deletions src/createos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def create_sandbox(
created = _one(CreateSandboxResponse, data)
sandbox = Sandbox(
snapshot_id=created.snapshot_id,
expires_at=created.expires_at,
sigterm_before_expiry=created.sigterm_before_expiry,
id=created.id,
status=created.status,
ip_address=created.ip_address,
Expand Down
10 changes: 10 additions & 0 deletions src/createos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ class CreateSandboxRequest(Model):
labels: dict[str, str] = _json(
"labels", omit_default=True, default_factory=dict
)
timeout_minutes: int = _json(
"timeout_minutes", omit_default=True, default=0
)
Comment on lines +257 to +259

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Undocumented zero timeout behavior

CreateSandboxRequest has no docstring explaining that zero omits the timeout rather than sending it for validation. The expiry guide lists only 2–1440 minutes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

sigterm_before_expiry: bool = _json(
"sigterm_before_expiry", omit_default=True, default=False
)
Comment on lines +257 to +262

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Misbound positional sandbox creation arguments

Existing positional calls to CreateSandboxRequest bind network lists and disk sizes to the new expiry fields. The SDK sends them under expiry keys instead of applying the requested network and disk settings.

Learn more

CreateSandboxRequest is a public dataclass, so its generated constructor accepts fields positionally in declaration order. Client.create_sandbox passes the request to the transport, which uses Model.to_dict to serialize the fields by name without checking their types.

Example: CreateSandboxRequest('', 's-4vcpu-4gb', 'devbox:1', 'demo', {}, [], 8192) used to send disk_mib: 8192 and omit the empty networks list. It now sends timeout_minutes: [] and sigterm_before_expiry: 8192 instead.

Recommended fix: Move both expiry fields after the existing request fields to preserve the public positional signature. Add a regression test that serializes a request using the old positional arguments.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

networks: list[NetworkEntry] = _json(
"networks", omit_default=True, default_factory=list
)
Expand Down Expand Up @@ -590,6 +596,8 @@ class CreateSandboxResponse(Model):
bandwidth_quota_bytes: int = 0
ingress_url_template: str = ""
snapshot_id: str | None = None
expires_at: datetime | None = None
sigterm_before_expiry: bool = False


@dataclass(slots=True)
Expand Down Expand Up @@ -621,6 +629,8 @@ class Sandbox(Model):
forked_from: str | None = None
auto_pause_after_seconds: int | None = None
snapshot_id: str | None = None
expires_at: datetime | None = None
sigterm_before_expiry: bool = False


@dataclass(slots=True)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def handler(request):
"status": "paused",
"name": "demo",
"labels": {"team": "backend"},
"expires_at": "2026-11-23T12:10:00Z",
"sigterm_before_expiry": True,
Comment on lines +229 to +230

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Unverified expiry wire contract

The test supplies expires_at and sigterm_before_expiry itself, so it cannot verify the control-plane response. The control-plane and Go SDK checkouts were unavailable for the required parity check.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

"ip": "10.0.0.2",
"shape": "s-4vcpu-4gb",
"mem_mib": 4096,
Expand All @@ -244,14 +246,20 @@ def handler(request):
shape="s-4vcpu-4gb",
name="demo",
labels={"team": "backend"},
timeout_minutes=10,
sigterm_before_expiry=True,
ingress_enabled=True,
)
)
assert requests[0].url.path == "/api/v1/sandboxes"
assert json.loads(requests[0].content)["labels"] == {"team": "backend"}
assert json.loads(requests[0].content)["timeout_minutes"] == 10
assert json.loads(requests[0].content)["sigterm_before_expiry"] is True
assert sandbox.id == "sb-1"
assert sandbox.status is SandboxStatus.PAUSED
assert sandbox.data.labels == {"team": "backend"}
assert sandbox.data.expires_at.isoformat() == "2026-11-23T12:10:00+00:00"
assert sandbox.data.sigterm_before_expiry is True
assert sandbox.files and sandbox.processes and sandbox.computer.mouse
assert sandbox.preview_url(8080) == "https://8080-sb-1.example.test"

Expand Down