Create the session ID in your backend. Pass it to the worker as
SESSION_ID. Keep the repository
name, branch name, and current commit SHA in the same session record.Create the session branch
Create an ephemeral branch from the repository’s normal default branch. One session branch holds every state of one session. Run this code in a trusted backend service. SetPIERRE_ORG to your organization slug. Set
PIERRE_PRIVATE_KEY to the private key in PEM format from the Code Storage dashboard. Do not give
this key to a sandbox.
base_ref can also be a full commit SHA. Use a full SHA when the session must start from an exact
state.
Save each state
Add one commit for each state that another process must read or restore. Each commit inherits unchanged files from the prior state, so send only changed or deleted paths.expected_target_sha lets the write succeed only if the branch still points to headSha. If
another writer changed the branch, the write fails with a RefGuardError. Stop the old writer and
reload the session record.
Store headSha in the backend session record after each successful write. See
repos.commits.create for file and stream inputs.
Exchange commit pointers
Pass a pointer instead of file contents. We recommend a repository name, a commit SHA, and an optional path.repos.files.get for files and repos.diff.get
for changes.
Confine a sandbox to its own session
A sandbox never holds your private key. Give each sandbox a credential with a short TTL. Useref_policies to confine that credential to the session’s own ref. The sandbox can then
fast-forward its own session branch only. It cannot change a normal branch or another session
branch.
A backend service that writes states through the API needs none of this. It signs each request with
the private key and never hands a credential out.
External Sandbox Integration
shows the URLs and the Git setup. See Ephemeral Namespace for namespace
details and Ref Policies for the rules of ref_policies.
Next steps
- Restore Agent State restores the latest state after a sandbox stops.
- Run Parallel Attempts creates several isolated branches from one state.
- Show Live Diffs renders the state as it changes.