# What Should I Keep Before Deleting a Coding Agent's Sandbox?

> Pin dropped commits from the reflog, then bundle every git ref with git bundle create --all, save the reflog as text, tar the agent's logs and notes, and save sbx history, then copy it out with sbx scp. To keep the whole disk instead, save a named snapshot. Deleting the sandbox deletes its history.

Source: https://sandboxer.com/guides/what-to-keep-before-deleting-a-coding-agents-sandbox. Updated 2026-11-21.

**Short answer:** Pin dropped commits from the reflog, then bundle every git ref with git bundle create --all, save the reflog as text, tar the agent's logs and notes, and save sbx history, then copy it out with sbx scp. To keep the whole disk instead, save a named snapshot. Deleting the sandbox deletes its history.

Part of [Coding Agents in the Cloud: Parallel, Overnight, Own Keys, Checkpoints](/guides/coding-agents-in-the-cloud).

You keep the final code and delete the box. What goes with it: the branches the agent dropped, its stash, its notes and logs, and the record of what ran. This page is the checklist for the minute before `sbx delete`. Its neighbors cover the rest: [checkpoint and roll back](/guides/checkpoint-and-roll-back-a-coding-agents-sandbox) is about going back *during* a run, [see what an agent did](/guides/see-what-an-ai-agent-did-in-its-sandbox) is about reading the evidence, and [move files in and out](/guides/move-files-in-and-out-of-a-sandbox) covers every copy method. Agents that run [overnight](/guides/run-a-coding-agent-overnight) or [in parallel](/guides/run-coding-agents-in-parallel) leave the most behind.

## What to keep, and how

| What | Command | Size, our run | Kept where |
| - | - | - | - |
| Every git ref: branches, tags, `refs/stash`, plus dropped commits you pin first | `git bundle create app.bundle --all` | 2,064 bytes | `app.bundle` on your machine |
| The reflog (not in any bundle) | `git reflog show --all > reflog.txt` | 1,095 bytes | `reflog.txt` on your machine |
| Agent logs, scratch notes, untracked files, `~/.claude` and `~/.codex` if they exist | `tar czf files.tgz …` | 417 bytes | `files.tgz` on your machine |
| Commands sent through the exec API, with their output | `sbx history <id> --json`, then `sbx history <id> <command-id>` | 4,232 bytes + 3 output files | `history.json` and `history/` on your machine |
| Everything on the disk | `sbx snapshot <id> <name>` | 20 GB disk; storage counts only the data beyond the shared OS image | Your account, until you delete it |
| Copy it out | `sbx scp -r <id>:/home/user/keep/. ./kept/` | 32K in all | Your machine |

Last checked: 2026-11-21, on prod

The first four rows fit in a few kilobytes for a small repo. The snapshot keeps everything, including things you didn't think to save, but it lives in your account and counts toward your storage until you remove it.

## What we ran

A scripted "agent" (a shell script, not a model) worked on a `slug()` function in a `small` sandbox. It tried three approaches on branches:

- `try-regex` failed the accented-letters test, and the agent deleted the branch with `git branch -D`.
- `try-ascii` failed too. The agent left the branch in place and moved on.
- `try-unicode` passed and was merged into `main`. Before merging, the agent stashed an untested `slug_max()` helper.

Along the way it wrote `~/agent-logs/run.log`, `~/NOTES.md` and an untracked `~/app/scratch.txt`. The whole script is in [Copy-paste](#copy-paste-keep-everything-delete-the-sandbox-restore-the-dropped-branch). It ran in 7.6 seconds end to end on 2026-11-21.

## 1. Git: bundle every ref, after pinning what's only in the reflog

`git bundle create … --all` packs every ref under `refs/`: branches, tags and `refs/stash`. It doesn't pack the reflog. A branch deleted with `git branch -D` is no longer a ref, so its commits live only in the reflog, and a plain `--all` bundle leaves them out. We checked by fetching a plain bundle into an empty repo:

```text
refs:
  refs/heads/main
  refs/heads/try-ascii
  refs/heads/try-unicode
  refs/stash
pinned from the reflog: refs/dropped/54f6a4d
  54f6a4d is NOT in a plain --all bundle
```

The fix is to turn every commit that's in a reflog but not reachable from a ref into a ref of its own, then bundle:

```bash
cd ~/app
git log -g --format=%H --all | sort -u > /tmp/logged      # every commit any reflog mentions
git rev-list --all | sort > /tmp/reach                     # every commit a ref reaches
for c in $(comm -23 /tmp/logged /tmp/reach); do git update-ref refs/dropped/${c:0:7} $c; done
git bundle create -q ~/keep/app.bundle --all
git reflog show --all > ~/keep/reflog.txt
```

Save the reflog as text too. The pinned ref has no branch name, and the reflog is where you find it:

```text
…
134abee refs/stash@{0}: On try-unicode: wip: slug_max, not tested
…
0c37006 HEAD@{8}: checkout: moving from try-regex to main
54f6a4d HEAD@{9}: commit: try regex slug
0c37006 HEAD@{10}: checkout: moving from main to try-regex
…
```

`refs/stash` is only the newest stash. Older ones (`stash@{1}` and up) are entries in the stash's reflog. The pin step walks every reflog, so it should catch them, but our run had a single stash.

A bundle also leaves out anything git never saw: untracked files like `scratch.txt`, ignored files, and anything outside the repo. That's the tarball's job.

## 2. The agent's own logs and notes

On a fresh `small` sandbox, neither agent folder exists yet:

```text
cannot access '/home/user/.claude': No such file or directory
cannot access '/home/user/.codex': No such file or directory
```

Claude Code and Codex are preinstalled, and each creates its folder in your home directory when it first runs. In an earlier sandbox, `codex --version` alone created `~/.codex`. We didn't run a model, so we didn't look inside a real transcript. The tarball takes the whole folder if it's there, along with whatever your own harness logs:

```bash
tar czf ~/keep/files.tgz -C ~ app/scratch.txt NOTES.md agent-logs $(cd ~ && ls -d .claude .codex 2>/dev/null)
```

Our tarball held `app/scratch.txt`, `NOTES.md` and `agent-logs/run.log`. Point it at your agent's log folder and any scratch files it writes. These folders can hold credentials, so treat the tarball like a secret.

## 3. The command history, before it's gone

`sbx history` lists the commands sent through the exec API, newest first, and prints each one's stored output by command id. `sbx history --help` and [command history](/docs/long-running#command-history) say commands run via exec or the API are kept 90 days, and output of other processes 72 hours. It's readable while a sandbox is stopped, not after it's deleted: right after `sbx delete`, `sbx history` answered `404 not_found`. Save it first:

```bash
sbx history "$id" --limit 100 --json > kept/history.json
for c in $(jq -r '.commands[].commandId' kept/history.json); do sbx history "$id" "$c" > "kept/history/$c.out"; done
```

```text
history: 3 commands
  cmd_xo9gl36tow6z  exit 0  set -e; cd ~/app; mkdir -p ~/keep echo "refs:"; gi
  cmd_xc56u22zewhv  exit 0  set -e; mkdir -p ~/app ~/agent-logs && cd ~/app &&
  cmd_eg70w4f36bfh  exit 0  ls -d ~/.claude ~/.codex 2>&1 | sed "s/^ls: //"
```

Know what it covers. Our whole "agent" was one exec call, so it is one line in the history; the git commands inside it aren't listed one by one. An agent running inside the sandbox works the same way: its tool calls are in its own transcript, not in `sbx history`. The `sbx scp` copy didn't appear in the list either. `--limit` goes up to 100 per call. [See what an agent did](/guides/see-what-an-ai-agent-did-in-its-sandbox) shows how to read the history and what it misses.

## 4. Copy it out

Put everything in one folder in the sandbox and copy the folder with `sbx scp`:

```bash
sbx scp -r "$id:/home/user/keep/." ./kept/
```

```text
kept locally: 32K
  2064 app.bundle
  417 files.tgz
  4232 history.json
  1095 reflog.txt
  3 files in history/
```

A tarball works the same way for bigger trees: tar them inside the sandbox, then `sbx scp` the one file. [Move files in and out of a sandbox](/guides/move-files-in-and-out-of-a-sandbox) compares `scp`, rsync, the SDK and pulling from a snapshot.

## 5. Or keep everything: a named snapshot

If you don't know yet what you'll want, save the whole disk under a name before you delete:

```bash
sbx snapshot "$id" "keep-${id#sb_}"
sbx snapshot info "keep-${id#sb_}" --json | jq -r '.snapshot | "  disk \(.sizeBytes / 1e9 | floor) GB, storedBytes \(.storedBytes)"'
```

```text
snapshot keep-6rqiqh9qh5: ready
  disk 20 GB, storedBytes null
```

It survives the delete, and `sbx new --from keep-6rqiqh9qh5` gives you the machine back, repo, stash, logs and all. 20 GB is the size of the disk, not what it stores; `storedBytes` was still `null` right after the save. What the docs say about cost and how long it's kept:

- [Snapshots](/docs/snapshots#named-snapshots-templates): "Named snapshots are kept until you delete them." and "Named snapshots have no separate charge; what they store counts toward your plan's included storage."
- [Billing](/docs/billing#storage): storage is "measured as the data beyond the shared OS image, about every 10 minutes", and each plan includes an amount. Plans start at $20/mo.

Nothing removes a named snapshot for you. Delete it with `sbx snapshot rm <name>` once you've pulled what you need. For saving several snapshots during a run, see [checkpoint and roll back](/guides/checkpoint-and-roll-back-a-coding-agents-sandbox).

## 6. Delete the sandbox, then restore the dropped branch

After `sbx delete`, `sbx info` and `sbx history` both answered `404 not_found`. On your machine, clone the bundle, fetch the refs a clone skips, and name the dropped commit from the reflog:

```bash
git clone -q kept/app.bundle restored && cd restored
git fetch -q origin 'refs/dropped/*:refs/dropped/*' 'refs/stash:refs/stash'
git branch try-regex "$(grep -m1 'commit: try regex slug' ../kept/reflog.txt | cut -d' ' -f1)"
git log --oneline -1 try-regex
git stash show -p refs/stash | grep '^+' | grep -v '^+++'
```

```text
54f6a4d try regex slug
+
+def slug_max(s, n=40):
+    return slug(s)[:n]
```

A clone maps only branches (`origin/main`, `origin/try-ascii`, `origin/try-unicode`); the extra fetch brings over `refs/dropped/*` and `refs/stash`. The deleted `try-regex` branch is back with its commit, and the stashed `slug_max()` is there to apply with `git stash apply refs/stash`.

## Copy-paste: keep everything, delete the sandbox, restore the dropped branch

After `curl -fsSL https://sandboxer.com/install | sh` and `sbx login`, save this as `keep-demo.sh` and run `bash keep-demo.sh` in an empty folder. It needs `git`, `jq` and OpenSSH `scp` on your machine. It creates one `small` sandbox and one named snapshot, and deletes both.

```bash
#!/usr/bin/env bash
# keep-demo.sh: a scripted "agent" tries 3 approaches in a sandbox. Before deleting the sandbox, keep
# every git ref (dropped branch and stash included), the reflog, logs, notes and the command history.
set -euo pipefail
AGENT=$(cat <<'EOF'
set -e; mkdir -p ~/app ~/agent-logs && cd ~/app && git init -q -b main
git config user.email agent@example.com && git config user.name agent
log() { echo "$(date -u +%T) $*" | tee -a ~/agent-logs/run.log; }
printf 'def slug(s):\n    return s.lower()\n' > slug.py
printf 'from slug import slug\nassert slug("Hello World") == "hello-world"\nassert slug("Crème Brûlée") == "creme-brulee"\nprint("tests pass")\n' > test_slug.py
git add -A && git commit -qm "base: failing slug()"
git switch -qc try-regex
printf 'import re\ndef slug(s):\n    return re.sub(r"[^a-z0-9]+", "-", s.lower()).strip("-")\n' > slug.py
git commit -qam "try regex slug"; python3 test_slug.py >/dev/null 2>&1 || log "try-regex: unicode test fails, dropping branch"
git switch -q main && git branch -qD try-regex
git switch -qc try-ascii
printf 'def slug(s):\n    return "-".join(s.encode("ascii", "ignore").decode().lower().split())\n' > slug.py
git commit -qam "try ascii slug"; python3 test_slug.py >/dev/null 2>&1 || log "try-ascii: drops accented letters, abandoned"
git switch -q main && git switch -qc try-unicode
printf 'import re, unicodedata\ndef slug(s):\n    s = unicodedata.normalize("NFKD", s).encode("ascii", "ignore").decode()\n    return re.sub(r"[^a-z0-9]+", "-", s.lower()).strip("-")\n' > slug.py
git commit -qam "unicode slug"; python3 test_slug.py && log "try-unicode: tests pass"
printf '\ndef slug_max(s, n=40):\n    return slug(s)[:n]\n' >> slug.py
git stash push -qm "wip: slug_max, not tested" && log "stashed slug_max for later"
git switch -q main && git merge -q --no-ff try-unicode -m "merge try-unicode"
echo "scratch: try python-slugify next time?" > ~/app/scratch.txt
printf '# agent notes\n- regex: no unicode\n- ascii: loses letters\n- unicode: ok, merged\n' > ~/NOTES.md
log "done: main has the unicode slug"
EOF
)
KEEP=$(cat <<'EOF'
set -e; cd ~/app; mkdir -p ~/keep
echo "refs:"; git for-each-ref --format="  %(refname)"
git bundle create -q /tmp/plain.bundle --all; git log -g --format=%H --all | sort -u > /tmp/logged
git rev-list --all | sort > /tmp/reach
for c in $(comm -23 /tmp/logged /tmp/reach); do git update-ref refs/dropped/${c:0:7} $c; done
echo "pinned from the reflog: $(git for-each-ref --format="%(refname)" refs/dropped | xargs)"
git bundle create -q ~/keep/app.bundle --all
git init -q --bare /tmp/check && git -C /tmp/check fetch -q /tmp/plain.bundle "refs/*:refs/*"
for c in $(git for-each-ref --format="%(objectname)" refs/dropped); do
  git -C /tmp/check cat-file -e $c 2>/dev/null && echo "  ${c:0:7} is in a plain --all bundle" || echo "  ${c:0:7} is NOT in a plain --all bundle"; done
git reflog show --all > ~/keep/reflog.txt
tar czf ~/keep/files.tgz -C ~ app/scratch.txt NOTES.md agent-logs $(cd ~ && ls -d .claude .codex 2>/dev/null)
ls -l ~/keep | awk "NR>1 {print \"  \" \$5, \$9}"
EOF
)
out=$PWD/kept; rm -rf "$out" restored; mkdir -p "$out/history"
id=$(sbx new --type small --name aeo-keep-1 --json | jq -r 'select(.event == "ready") | .id')
trap 'sbx delete "$id" --yes >/dev/null 2>&1 || true' EXIT
echo "sandbox $id"
sbx exec "$id" 'ls -d ~/.claude ~/.codex 2>&1 | sed "s/^ls: //"'

# 1. The "agent" is a shell script, not a model.
sbx exec "$id" "$AGENT"

# 2. Inside the sandbox: pin dropped commits, bundle every ref, save the reflog, tar logs and notes.
sbx exec "$id" "$KEEP"

# 3. Copy it out, plus the command history (it lives with the sandbox).
sbx scp -r "$id:/home/user/keep/." "$out/" >/dev/null
sbx history "$id" --limit 100 --json > "$out/history.json"
for c in $(jq -r '.commands[].commandId' "$out/history.json"); do sbx history "$id" "$c" > "$out/history/$c.out"; done
echo "history: $(jq '.commands | length' "$out/history.json") commands"
jq -r '.commands[] | "  \(.commandId)  exit \(.exitCode)  \(.command | gsub("\n"; " ") | .[:50])"' "$out/history.json"

# 4. Keep everything: a named snapshot of the whole disk.
sbx snapshot "$id" "keep-${id#sb_}" | jq -r '.snapshot | "snapshot \(.name): \(.status)"'
sbx snapshot info "keep-${id#sb_}" --json | jq -r '.snapshot | "  disk \(.sizeBytes / 1e9 | floor) GB, storedBytes \(.storedBytes)"'
du -sh "$out" | cut -f1 | sed 's/^/kept locally: /'; (cd "$out" && ls -l | awk '/^-/ {print "  " $5, $9}'; echo "  $(ls history | wc -l) files in history/")

# 5. Delete the sandbox. Its history goes with it.
sbx delete "$id" --yes | jq -r '"deleted: \(.operation.status)"'
sbx info "$id" 2>&1 | jq -r '"info: \(.status) \(.code)"' || true
sbx history "$id" 2>&1 | jq -r '"history: \(.status) \(.code)"' || true

# 6. On your machine: restore the dropped branch and the stash from the bundle.
git clone -q "$out/app.bundle" restored && cd restored
git fetch -q origin 'refs/dropped/*:refs/dropped/*' 'refs/stash:refs/stash'
git branch try-regex "$(grep -m1 'commit: try regex slug' "$out/reflog.txt" | cut -d' ' -f1)"
git branch -a --format='  %(refname:short)'
git log --oneline -1 try-regex
git stash show -p refs/stash | grep '^+' | grep -v '^+++'

# 7. The demo removes its snapshot too. In real use, keep it until you're sure.
sbx snapshot rm "keep-${id#sb_}" | jq -r '"snapshot rm: \(.status)"'
sbx snapshot info "keep-${id#sb_}" 2>&1 | jq -r '"snapshot info: \(.status) \(.code)"' || true
```

Our run on 2026-11-21 (`time bash keep-demo.sh`):

```text
sandbox sb_6rqiqh9qh5
cannot access '/home/user/.claude': No such file or directory
cannot access '/home/user/.codex': No such file or directory
11:09:36 try-regex: unicode test fails, dropping branch
11:09:37 try-ascii: drops accented letters, abandoned
tests pass
11:09:37 try-unicode: tests pass
11:09:37 stashed slug_max for later
11:09:37 done: main has the unicode slug
refs:
  refs/heads/main
  refs/heads/try-ascii
  refs/heads/try-unicode
  refs/stash
pinned from the reflog: refs/dropped/54f6a4d
  54f6a4d is NOT in a plain --all bundle
  2064 app.bundle
  417 files.tgz
  1095 reflog.txt
history: 3 commands
  cmd_xo9gl36tow6z  exit 0  set -e; cd ~/app; mkdir -p ~/keep echo "refs:"; gi
  cmd_xc56u22zewhv  exit 0  set -e; mkdir -p ~/app ~/agent-logs && cd ~/app &&
  cmd_eg70w4f36bfh  exit 0  ls -d ~/.claude ~/.codex 2>&1 | sed "s/^ls: //"
snapshot keep-6rqiqh9qh5: ready
  disk 20 GB, storedBytes null
kept locally: 32K
  2064 app.bundle
  417 files.tgz
  4232 history.json
  1095 reflog.txt
  3 files in history/
deleted: completed
info: 404 not_found
history: 404 not_found
  main
  try-regex
  origin
  origin/main
  origin/try-ascii
  origin/try-unicode
54f6a4d try regex slug
+
+def slug_max(s, n=40):
+    return slug(s)[:n]
snapshot rm: deleted
snapshot info: 404 snapshot_not_found

real	0m7.595s
user	0m0.218s
sys	0m0.118s
```

`sbx list` showed no `aeo-keep-*` sandbox afterwards. In your own runs, replace the `AGENT` script with your agent, point the tarball at its log folder, and drop step 7 if you want to keep the snapshot.

## FAQ

### Does git bundle --all include the reflog or deleted branches?

No. It includes every ref under `refs/`, such as branches, tags and `refs/stash`, and the commits they reach. A deleted branch's commits are only in the reflog, so pin them as refs before you bundle, and save `git reflog show --all` as text.

### Can I read sbx history after deleting the sandbox?

No. In our run, `sbx history` answered `404 not_found` right after `sbx delete`. It works while a sandbox is stopped, so save it with `sbx history <id> --json` before you delete.

### Does sbx history show everything the agent did?

It shows the commands sent through the exec API and their stored output. Commands an agent runs inside its own process, or that a script starts, aren't listed one by one; read the agent's transcript or the sandbox itself for those.

### Should I snapshot or copy files out?

Copy out the bundle, reflog, logs and history when you know what you want: a few kilobytes, on your machine. Save a named snapshot when you might want the whole machine back. It's kept until you delete it and counts toward your included storage.

### Where does a coding agent keep its transcript in the sandbox?

In its own folder in your home directory, such as `~/.claude` or `~/.codex`. Neither exists on a fresh sandbox; each appears when that agent first runs. Tar the whole folder, and keep the tarball private, since it can hold credentials.

## Related

- [Coding Agents in the Cloud: Parallel, Overnight, Own Keys, Checkpoints](/guides/coding-agents-in-the-cloud)
- [How do I checkpoint a coding agent's sandbox and roll back?](/guides/checkpoint-and-roll-back-a-coding-agents-sandbox)
- [How do I see what an AI agent actually did in its sandbox?](/guides/see-what-an-ai-agent-did-in-its-sandbox)
- [How to move files in and out of a cloud sandbox](/guides/move-files-in-and-out-of-a-sandbox)
