What ephemeral sessions are
An ephemeral session is a temporary agent identity that expires on its own. You create one, hand the token to an AI agent, and the token stops working when the TTL runs out or the agent exhausts its action budget, whichever comes first. The pattern is designed for computer-use agents (Claude computer use, GPT browsing, operator loops) that need just enough access to complete one task without holding persistent credentials across invocations. Key differences from a regular agent:| Regular agent | Ephemeral session | |
|---|---|---|
| Lifetime | Indefinite by default | Bounded TTL (default 5 min) |
| Token | Rotatable, persistent | Single-use window |
| Cleanup | Manual revocation | Automatic |
| Action budget | None | Optional hard cap |
| Audit | Per-agent | Grouped under one session ID |
Setup
No extra configuration is needed, ephemeral sessions are part of thekavachos core package and share the same database as the rest of KavachOS.
Creating a session for a computer-use agent
CallcreateSession right before you hand control to the agent. The token is shown exactly once.
token starts with kveph_ to distinguish it from long-lived agent tokens (kv_).
Validating a session
Each time the agent makes a request, validate the token before granting access.expiresIn is in seconds. remainingActions is null when no action cap was set.
Tracking actions
CallconsumeAction once per agent action to decrement the budget counter.
actionsRemaining hits zero, the session transitions to exhausted and the underlying agent is automatically revoked.
Action limits
maxActions is a hard cap on how many times consumeAction can succeed. It is independent of the TTL, a session can expire by time with actions remaining, or exhaust its action budget before the TTL lapses.
Set a tight budget for tasks with a well-known scope and leave it as null for tasks where the step count is unpredictable.
Revoking early
If the agent completes the task before the TTL expires, revoke the session manually.Listing active sessions
Useful for dashboards or for building kill-switch UI.token set to "", the token is never readable after the initial createSession response.
Cleanup strategies
Two approaches to cleaning up expired sessions:Scheduled background job
RuncleanupExpired() on a cron schedule, every minute for busy systems, every 5 minutes for lighter loads.
On-demand at validate time
validateSession already detects and transitions expired sessions. For low-traffic systems, this is enough, no background job needed.
Audit grouping
WhenauditGrouping: true (the default), all actions within a session share the same auditGroupId. This makes it trivial to reconstruct the full activity trace for a single task.
Session status lifecycle
active, it cannot be reactivated. Create a new session for a new task.
Error codes
| Code | Meaning |
|---|---|
SESSION_NOT_FOUND | Token does not match any session |
SESSION_EXPIRED | TTL has elapsed |
SESSION_EXHAUSTED | Action budget is fully consumed |
SESSION_REVOKED | Manually revoked |
TTL_EXCEEDS_MAX | Requested TTL is above maxTtlSeconds |
VALIDATION_ERROR | Input failed schema validation (e.g. empty permissions) |