While Blaxel is designed for you to keep your sandboxes in standby perpetually, it also supports automatic deletion of sandboxes based on specific expiration policies. This is useful if you want to avoid keeping snapshot storage for a long tail of sandboxes that will never be reactivated again.
Blaxel has a quota tiering system that unlocks higher limits and features on the platform as your tier progresses. Some quota tiers enforce expiration dates (Tier 0 and 1, with respectively up to 7 and 30 days). In higher tiers, unlimited persistence is permitted.
Automatic deletion differs from the automatic standby (scale-to-zero) which happens toall sandboxes when inactive and where the memory and filesystem are snapshotted to be resumed instantly.
Expiration policies
The following options are available for sandbox expiry and deletion:
- expire after a total maximum lifetime (time-to-live or TTL) using the
ttl parameter
- expire after a period of inactivity using the
lifecycle.expirationPolicies / lifecycle.expiration_policies parameter
- expire at a specific date using the
expires parameter
If these parameters are absent, sandboxes will not be deleted.
You can define a sandbox’s time-to-live (TTL) configuration at creation time:
import { SandboxInstance } from "@blaxel/core";
// Create a new sandbox
const sandbox = await SandboxInstance.create({
name: "my-sandbox",
image: "blaxel/base-image:latest",
memory: 4096,
ports: [{ target: 3000, protocol: "HTTP" }],
region: "us-pdx-1",
ttl: "24h", // Total duration before auto-deletion. Supported units: h, d, w
// OR
// expires: new Date(Date.now() + 86400000) // Alternative: set a date at which it will be deleted
// OR / AND
lifecycle: {
expirationPolicies: [
{
type: "ttl-idle",
value: "24h", // Delete after 24 hours of inactivity. Supported units: h, d, w
action: "delete"
}
]
}
});
Important notes:
- The
ttl parameter accepts a string with the following time units: h (hours), d (days), and w (weeks).
- Lifecycle expirations policies also support types
ttl-max-age and date: check out the API reference for full documentation.
- You can combine multiple expiration policies. Whichever condition is met first will trigger the deletion.
Update sandbox expiry rules
You can update a sandbox’s time-to-live (TTL) configuration after it has been created:
import { SandboxInstance } from "@blaxel/core";
// Update sandbox TTL
const sandbox = await SandboxInstance.updateTtl("my-sandbox", "30m");
You can also update the expiration policy of a sandbox after it has been created:
import { SandboxInstance } from "@blaxel/core";
// Update sandbox expiration policy
await SandboxInstance.updateLifecycle("my-sandbox", {
expirationPolicies: [
{ type: "ttl-max-age", value: "30m", action: "delete" }
]
});