Local-first receipts and safe undo for AI agents
pip install glassbox-agent Copy PIP instructions
Your AI agent changed a file. Glassbox shows what happened—and gives you a guarded way back.
Run the demo · Read the security model · Download the latest release · Share feedback
Glassbox is a local-first action ledger for AI agents—a flight recorder with guarded rollback for eligible text-file changes. A bundled Claude Code hook, a command-line tool, or any integration submits actions to Glassbox after execution. Glassbox records a plain-language receipt, redacts common secret formats, assigns deterministic risk, and chains the receipt with HMAC-SHA256 so later tampering is detectable.
For file edits, creations, and deletions, integrations can submit the previous and resulting text. Glassbox encrypts the previous state and the diff locally and will undo the change only if the complete receipt chain verifies and live filesystem checks show that rollback will not overwrite newer work.
AI agents can edit files, execute commands, and communicate on a user's behalf. Chat history is not an operational audit trail, and a generic backup does not answer whether a particular agent action is still safe to reverse. Glassbox gives each submitted action a durable receipt:
git clone https://github.com/jckm14/glassbox.git cd glassbox uv sync --locked --group dev Create a populated local demo:
uv run glassbox demo \ --workspace ./demo-workspace \ --data-dir ./.glassbox-data Demo generation uses exclusive file creation and refuses to overwrite an existing launch-plan.md. Actions that are not actually executed by the generator are explicitly labeled as synthetic sample receipts.
uv run glassbox serve \ --host 127.0.0.1 \ --port 8765 \ --workspace ./demo-workspace \ --data-dir ./.glassbox-data Open http://127.0.0.1:8765. Because the MVP has no remote authentication, the CLI accepts only 127.0.0.1 or localhost as bind hosts and refuses wildcard or non-loopback addresses.
Glassbox ships a Claude Code hook. Print the settings and merge them into .claude/settings.json in your project (or ~/.claude/settings.json for every project):
glassbox hook claude-code --print-config { "hooks": { "PreToolUse": [ { "matcher": "Write|Edit|MultiEdit|NotebookEdit", "hooks": [{ "type": "command", "command": "glassbox hook claude-code", "timeout": 15 }] } ], "PostToolUse": [ { "matcher": "Write|Edit|MultiEdit|NotebookEdit|Bash", "hooks": [{ "type": "command", "command": "glassbox hook claude-code", "timeout": 15 }] } ], "PostToolUseFailure": [ { "matcher": "Write|Edit|MultiEdit|NotebookEdit|Bash", "hooks": [{ "type": "command", "command": "glassbox hook claude-code", "timeout": 15 }] } ] } } glassbox must be on the PATH Claude Code uses; otherwise put the absolute path to the executable in command. From then on:
The hook works with or without a running server: it writes to the ledger directly, or hands the receipt to glassbox serve when the server owns the ledger. It never blocks or fails a tool call; problems are printed to stderr. The ledger defaults to ~/.glassbox; pass --data-dir (or set GLASSBOX_DATA_DIR) to keep one per project, and start glassbox serve with the same directory and the project as --workspace.
Before an edit runs, the hook holds the file's current text, unencrypted, in /pending/ (a mode-0700 directory). It is removed when the edit succeeds or fails; text left behind by an edit that never ran, such as one you denied, is removed by the next edit hook once it is an hour old. Content is recorded only for UTF-8 files up to 1 MB inside the workspace; other files get a receipt without content.
Every command takes --data-dir. Read commands work while the server is running; record and rollback are handed to the server when it owns the ledger.
Receipt HMACs cannot show that the newest receipts were deleted. To detect that, save the output of glassbox head somewhere the agent cannot write, and later run glassbox verify --expect-head HASH: it fails if that receipt is no longer in the chain.
From Python, glassbox.client.GlassboxClient wraps the HTTP API using only the standard library:
from glassbox.client import GlassboxClient GlassboxClient().record( agent="my-agent", action="file.write", target="notes/plan.md", summary="Updated the project plan", before_text=old_text, after_text=new_text, ) Record an action Want a runnable tool example first? Try the file-tool integration demo to verify a successful rollback and a refused rollback after a newer edit, using disposable files and no model credentials.
curl -X POST http://127.0.0.1:8765/api/events \ -H 'Content-Type: application/json' \ -d '{ "agent": "my-agent", "action": "file.write", "target": "notes/plan.md", "summary": "Updated the project plan", "before_text": "old content", "after_text": "new content", "metadata": {"tool": "write_file"} }' The API returns the receipt ID, risk label, content hashes, previous receipt hash, and receipt hash. Raw snapshots are never returned by the API.
Glassbox accepts arbitrary action names and labels each receipt from the words in the action name and from the target. The same submission always gets the same label, and the receipt records the reason.
For a shell action, the command is read from metadata.command when present, otherwise from target. Labels are a triage aid based on pattern matching, not a sandbox: a command Glassbox labels medium can still be destructive. Commands longer than 20,000 characters, or with a single statement longer than 2,000, are labeled high without analysis.
Glassbox encrypts before_text for restoration, hashes after_text for conflict detection, and stores an encrypted diff. A recreated file gets mode 0600 unless the receipt's metadata.mode records the original permission bits (for example "0644"); group and other write bits and setuid bits are never restored. If metadata.workspace is present, rollback refuses to run in any other workspace.
The agent name glassbox and the actions file.rollback and snapshot.prune are reserved for receipts Glassbox writes itself; the API and CLI reject submissions that use them.
curl http://127.0.0.1:8765/api/verify Example:
{"valid": true, "event_count": 4, "broken_at": null} If an authenticated receipt field or encrypted snapshot is modified so that its signed semantics change, or a snapshot file is missing without a signed prune receipt that names it, valid becomes false and broken_at identifies the first affected receipt. Semantically equivalent JSON reformatting is normalized during verification and is not treated as tampering.
Rollback uses an atomic directory-fd-relative filesystem exchange, then validates both the installed restore-candidate inode and the displaced inode identity, type, content, owner UID/GID, file mode, and POSIX access ACL. It also rechecks workspace/parent identities against the no-follow workspace descriptor held from application startup. If the candidate, target entry, ownership/access policy, parent, or configured workspace identity changed—or synchronous validation fails after exchange—Glassbox exchanges the displaced entry back and returns HTTP 409. Restore candidates preserve the target owner UID/GID, mode, and POSIX access ACL while stripping inherited ACLs from the private recovery directory. Preservation intent is set before each exchange so an exception immediately after the syscall cannot trigger destructive cleanup. Restore candidates and retained inodes live inside a newly created mode-0700 recovery directory in the target's parent filesystem. The retained inode keeps its original ownership and file mode rather than being chmodded or chowned, avoiding metadata changes through hard-link aliases outside the workspace; access is restricted by the private directory. Once an exchange has occurred, Glassbox retains that inode—on success, conflict, or compensation—and reports its path, so late writes through a descriptor opened before exchange remain linked and recoverable. Rollback receipts carry a unique operation identifier generated before filesystem mutation: if persistence raises after commit, Glassbox reconciles the committed receipt rather than compensating the filesystem into a contradictory state. Review and remove recovery directories only after external writers are quiescent. A successful rollback produces a new receipt; Glassbox never silently rewrites history.
Rolling back a file.create or file.delete receipt applies the same chain, workspace, parent-directory, and no-follow checks, and uses an atomic no-replace rename instead of an exchange:
GET /api/events returns events, the total number of matching receipts, and next_before_id to pass as before_id for the next page.
uv sync --locked --group dev uv run ruff format --check src tests scripts/render-launch-server.py scripts/validate-launch-assets.py scripts/publish-launch-assets.py uv run ruff check src tests scripts/render-launch-server.py scripts/validate-launch-assets.py scripts/publish-launch-assets.py shellcheck scripts/render-launch-assets.sh uv run mypy src scripts/render-launch-server.py scripts/validate-launch-assets.py scripts/publish-launch-assets.py uv run python -m compileall -q src tests scripts/render-launch-server.py scripts/validate-launch-assets.py scripts/publish-launch-assets.py uv run pytest -q uv build See CONTRIBUTING.md before opening a pull request. Report suspected vulnerabilities privately according to SECURITY.md, not through public issues.
If Glassbox is useful to you or your team, sponsor its development. Your support helps fund maintenance, security-focused testing, documentation, and integration examples.
Read how sponsorship supports Glassbox. Bug reports, documentation improvements, and code contributions are welcome too.
Glassbox is licensed under the Apache License 2.0.
The API and rollback behavior are developed test-first. The suite covers recursive and compound sensitive-key redaction, valid and tampered receipt chains, malformed database values, encrypted-snapshot tampering, protected single-link key/database handling, complete rollback eligibility, atomic-exchange conflicts, same-content inode substitution, post-exchange interruption, post-commit receipt reconciliation, creation and deletion rollback races, snapshot-file substitution, signed pruning, legacy-ledger migration, reserved-name rejection, content-aware risk labels, the Claude Code hook, the single-writer lock, pinned-workspace identity, parent-directory and final-symlink substitution, hard-link alias safety, POSIX ACL preservation, private recovery directories, chain-gated rollback, receipt-failure compensation races, workspace escape attempts, concurrent receipt writers, DNS-rebinding/canonical-Origin defenses, non-loopback bind refusal, dashboard security, and safe CLI demo generation.
ai-agents audit-log local-first rollback security
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.




