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 @@ -7,6 +7,8 @@ Versioning and the Keep a Changelog structure.

### Added

- Optional sandbox expiry through `CreateSandboxRequest.Builder.timeoutMinutes()`,
with `expiresAt()` response fields and an optional final-minute SIGTERM warning.
- Checkpoint create, list, restore, and delete operations scoped to
a running sandbox through `Sandbox.checkpoints()`.
- Reusable disk and full snapshot create, get, list, and delete operations,
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ sandbox.setLabels(Map.of("environment", "production"));
List filters use AND semantics. `setLabels()` merges the supplied keys into the
existing label map.

## Limit sandbox lifetime

```java
Sandbox sandbox = client.createSandbox(
CreateSandboxRequest.builder("s-1vcpu-1gb")
.rootFileSystem("devbox:1")
.timeoutMinutes(10)
.sigtermBeforeExpiry(true)
.build());

System.out.println(sandbox.data().expiresAt());
```

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

## Capture and restore snapshots

```java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ public static void main(String[] arguments) {
CreateOsClient.builder().apiKey(System.getenv("CREATEOS_API_KEY")).build();
Sandbox sandbox =
client.createSandbox(
CreateSandboxRequest.builder("s-4vcpu-4gb").rootFileSystem("devbox:1").build());
CreateSandboxRequest.builder("s-4vcpu-4gb")
.rootFileSystem("devbox:1")
.timeoutMinutes(10)
.sigtermBeforeExpiry(true)
.build());
System.out.printf(
"expires_at=%s sigterm_before_expiry=%s%n",
sandbox.data().expiresAt(), sandbox.data().sigtermBeforeExpiry());
try {
var response =
sandbox.runCommand(
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/sh/createos/CreateOsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ public Sandbox createSandbox(CreateSandboxRequest request) {
null,
request.autoPauseAfterSeconds(),
created.labels(),
created.snapshotId());
created.snapshotId(),
created.expiresAt(),
created.sigtermBeforeExpiry());
return new Sandbox(transport, data);
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/sh/createos/Sandbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,9 @@ private static SandboxData copyWithStatus(SandboxData source, SandboxStatus stat
source.forkedFrom(),
source.autoPauseAfterSeconds(),
source.labels(),
source.snapshotId());
source.snapshotId(),
source.expiresAt(),
source.sigtermBeforeExpiry());
}

private record DestroyedResponse(String id, SandboxStatus status) {}
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/sh/createos/model/CreateSandboxRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public record CreateSandboxRequest(
String region,
@JsonProperty("auto_pause_after_seconds") Integer autoPauseAfterSeconds,
Map<String, String> labels,
@JsonProperty("snapshot_id") String snapshotId) {
@JsonProperty("snapshot_id") String snapshotId,
@JsonProperty("timeout_minutes") Integer timeoutMinutes,
@JsonProperty("sigterm_before_expiry") Boolean sigtermBeforeExpiry) {
Comment on lines +26 to +28

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: Snapshot constructor compatibility gap

The expiry components replace the snapshot-aware constructors on CreateSandboxRequest, CreateSandboxResponse, and SandboxData. Only the older overloads remain.

Devin Review


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

/** Validates required values and defensively copies collection values. */
public CreateSandboxRequest {
if ((shape == null || shape.isBlank()) && (snapshotId == null || snapshotId.isBlank())) {
Expand Down Expand Up @@ -71,6 +73,8 @@ public CreateSandboxRequest(
region,
autoPauseAfterSeconds,
Map.of(),
null,
null,
null);
}

Expand Down Expand Up @@ -107,6 +111,8 @@ public CreateSandboxRequest(
region,
autoPauseAfterSeconds,
labels,
null,
null,
null);
}

Expand Down Expand Up @@ -138,6 +144,8 @@ public static final class Builder {
private Integer autoPauseAfterSeconds;
private Map<String, String> labels = Map.of();
private String snapshotId;
private Integer timeoutMinutes;
private Boolean sigtermBeforeExpiry;

private Builder(String shape) {
this.shape = shape;
Expand All @@ -161,6 +169,18 @@ public Builder labels(Map<String, String> labels) {
return this;
}

/** Sets the absolute lifetime in whole minutes (2-1440) from first reaching running. */
public Builder timeoutMinutes(int timeoutMinutes) {
this.timeoutMinutes = timeoutMinutes;
return this;
}

/** Requests a best-effort SIGTERM warning in the final minute. Requires a timeout. */
public Builder sigtermBeforeExpiry(boolean sigtermBeforeExpiry) {
this.sigtermBeforeExpiry = sigtermBeforeExpiry;
return this;
}

/** Restores an owned ready reusable snapshot instead of a root filesystem. */
public Builder snapshotId(String snapshotId) {
this.snapshotId = snapshotId;
Expand Down Expand Up @@ -251,7 +271,9 @@ public CreateSandboxRequest build() {
region,
autoPauseAfterSeconds,
labels,
snapshotId);
snapshotId,
timeoutMinutes,
sigtermBeforeExpiry);
Comment on lines +274 to +276

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Server-only expiry validation

build() accepts out-of-range lifetimes and requests for SIGTERM without a lifetime. The SDK sends both without checking them locally.

Devin Review


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

}
}
}
13 changes: 10 additions & 3 deletions src/main/java/sh/createos/model/CreateSandboxResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.Instant;
import java.util.List;
import java.util.Map;

Expand All @@ -22,7 +23,9 @@ public record CreateSandboxResponse(
@JsonProperty("bandwidth_quota_bytes") long bandwidthQuotaBytes,
@JsonProperty("ingress_url_template") String ingressUrlTemplate,
Map<String, String> labels,
@JsonProperty("snapshot_id") String snapshotId) {
@JsonProperty("snapshot_id") String snapshotId,
@JsonProperty("expires_at") Instant expiresAt,
@JsonProperty("sigterm_before_expiry") boolean sigtermBeforeExpiry) {
/** Normalizes missing labels and keeps the response immutable. */
public CreateSandboxResponse {
labels = labels == null ? Map.of() : Map.copyOf(labels);
Expand Down Expand Up @@ -58,7 +61,9 @@ public CreateSandboxResponse(
bandwidthQuotaBytes,
ingressUrlTemplate,
Map.of(),
null);
null,
null,
false);
}

/** Creates a response with labels, preserving the pre-snapshots constructor. */
Expand Down Expand Up @@ -92,6 +97,8 @@ public CreateSandboxResponse(
bandwidthQuotaBytes,
ingressUrlTemplate,
labels,
null);
null,
null,
false);
}
}
12 changes: 9 additions & 3 deletions src/main/java/sh/createos/model/SandboxData.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public record SandboxData(
@JsonProperty("forked_from") String forkedFrom,
@JsonProperty("auto_pause_after_seconds") Integer autoPauseAfterSeconds,
Map<String, String> labels,
@JsonProperty("snapshot_id") String snapshotId) {
@JsonProperty("snapshot_id") String snapshotId,
@JsonProperty("expires_at") Instant expiresAt,
@JsonProperty("sigterm_before_expiry") boolean sigtermBeforeExpiry) {
/** Defensively copies collection values. */
public SandboxData {
egressRules = egressRules == null ? List.of() : List.copyOf(egressRules);
Expand Down Expand Up @@ -99,7 +101,9 @@ public SandboxData(
forkedFrom,
autoPauseAfterSeconds,
Map.of(),
null);
null,
null,
false);
}

/** Creates a projection with labels, preserving the pre-snapshots constructor. */
Expand Down Expand Up @@ -157,6 +161,8 @@ public SandboxData(
forkedFrom,
autoPauseAfterSeconds,
labels,
null);
null,
null,
false);
}
}
8 changes: 7 additions & 1 deletion src/test/java/sh/createos/CreateOsClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void createsSandboxWithExpectedWireNames() {
exchange,
200,
"""
{"status":"success","data":{"id":"sb-1","status":"running","labels":{"team":"backend"},"ip":"10.0.0.2","shape":"s-4vcpu-4gb","rootfs":"devbox:1","vcpu":4,"mem_mib":4096,"disk_mib":8192,"spawn_ms":42.5,"egress":[],"ingress_url_template":"https://<port>.example.test"}}
{"status":"success","data":{"id":"sb-1","status":"running","labels":{"team":"backend"},"expires_at":"2026-11-23T12:10:00Z","sigterm_before_expiry":true,"ip":"10.0.0.2","shape":"s-4vcpu-4gb","rootfs":"devbox:1","vcpu":4,"mem_mib":4096,"disk_mib":8192,"spawn_ms":42.5,"egress":[],"ingress_url_template":"https://<port>.example.test"}}
""");
});

Expand All @@ -100,6 +100,8 @@ void createsSandboxWithExpectedWireNames() {
CreateSandboxRequest.builder("s-4vcpu-4gb")
.rootFileSystem("devbox:1")
.labels(Map.of("team", "backend"))
.timeoutMinutes(10)
.sigtermBeforeExpiry(true)
.ingressEnabled(true)
.build());

Expand All @@ -108,7 +110,11 @@ void createsSandboxWithExpectedWireNames() {
assertTrue(requestBody.get().contains("\"rootfs\":\"devbox:1\""));
assertTrue(requestBody.get().contains("\"ingress_enabled\":true"));
assertTrue(requestBody.get().contains("\"labels\":{\"team\":\"backend\"}"));
assertTrue(requestBody.get().contains("\"timeout_minutes\":10"));
assertTrue(requestBody.get().contains("\"sigterm_before_expiry\":true"));
assertEquals(Map.of("team", "backend"), sandbox.labels());
assertEquals(java.time.Instant.parse("2026-11-23T12:10:00Z"), sandbox.data().expiresAt());
assertTrue(sandbox.data().sigtermBeforeExpiry());
Comment on lines +116 to +117

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Expiry tests stop at creation

The create test covers CreateSandboxResponse only. No contract test checks that lookup or refresh retains expiry through SandboxData.

Devin Review


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

assertFalse(requestBody.get().contains("disk_mib"));
}

Expand Down