The pattern
getOrCreate({ name: "agent-session-42" }) call resumes the same filesystem state, no explicit snapshot id to track or pass around yourself.
How it works underneath
getOrCreate resolves to one of three outcomes, race-safe under a per-name lock so two concurrent callers for a brand-new name can’t both create a sandbox:
- A live sandbox with this name → returned as-is.
- A stopped (snapshotted) one → resumed.
- Neither → created fresh, given this name.
If you need it gone for good
getOrCreate never deletes anything — call sandbox.stop({ keep: false }) explicitly (or kiln sandbox rm --destroy) when you’re genuinely done with that identity and don’t want the snapshot left behind.