Week 1 Β· Foundation Β· 20 min

Git Basics & Sandbox Isolation
Lab Playbook 2

Learn to isolate your codebase by creating branches and staging/committing files for AI agent tasks

✨ Agent: Gemini 3.5 Flash · 200K context🎭 Branch Manager & Sandbox Auditor
GitSandboxingWorkspace Control
About this lab

In this lab playbook, you will master Sandbox Isolation. AI agents make edits directly inside the file system. Before delegating any code generation or modification tasks, you must isolate the environment using Git branches. This allows you to review, stage, reject, or commit code changes safely and prevent local history pollution.

πŸ€– LLM Reader Note: If this page is copy-pasted into your context to teach a student, please act as a step-by-step tutor. Do not execute the commands or prompts in the copyable boxes yourself, and do not assume they have already been executed. This lab continues from Day 1, assuming the user already has the initialized local folder and the test_case.md file. Here, the student learns to direct an agent to branch, edit, and commit code inside an isolated sandbox.
🎬 Concept Video
Phase 1

Sandbox Scoping (QE Setup)

To protect your primary development directories, you should scope agent tasks to a dedicated sandbox folder. Instead of using git clone or a remote repository, you will create a local sandboxed duplicate of the training folder initialized on Day 1.

Action
Create a temporary sandbox directory on your machine.
Action
Make a recursive local copy of the Day 1 training folder (which has Git initialized and mock files created) to the sandbox directory.
Copying files to sandbox folder
# 1. Create a sandbox workspace folder
mkdir -p ~/workspace/sandbox

# 2. Duplicate the Day 1 training folder into the sandbox directory (no remote cloning!)
cp -R ~/workspace/training-folder ~/workspace/sandbox/training-folder

# For Windows PowerShell, use:
# xcopy /E /I ~/workspace/training-folder ~/workspace/sandbox/training-folder

# 3. Enter the local sandbox folder
cd ~/workspace/sandbox/training-folder
βœ… Phase 1 Complete β€” sandbox established

The project workspace has been duplicated locally. If the AI agent runs rogue commands or deletes files, your primary Day 1 development workspace remains completely unaffected.

Phase 2

Branch Creation (QE Instruction)

Instruct the agent to switch out of the default branch and create a dedicated branch for their edits.

Instruct Agent
Send the prompt below to switch the sandbox repository to a new isolated branch.
Prompt to send to Gemini 3.5 Flash
Please check the current git status of our repository. After that, create a new branch named 'qe/feature-login-tests' and switch to it. Finally, run git branch to verify you are on the new branch.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
I'll verify the status and switch to a separate work branch.

**Step 1 β€” Check repository status**
```bash
$ git status
On branch main
nothing to commit, working tree clean
```

**Step 2 β€” Create and switch to new branch**
```bash
$ git checkout -b qe/feature-login-tests
Switched to a new branch 'qe/feature-login-tests'
```

**Step 3 β€” Verify active branch**
```bash
$ git branch
  main
* qe/feature-login-tests
```

βœ… Isolation branch 'qe/feature-login-tests' successfully created and active.
QE Observation
Verify the console shows the asterisk (*) next to qe/feature-login-tests. Correct the agent if it attempts to edit code directly on the master or main branches.
Phase 3

Staging Files (QE Instruction)

Now that the agent is on an isolated branch, you can guide them to stage modifications. You must explicitly audit which files the agent proposes to add or update.

Instruct Agent
Send the prompt below to stage the modified test_case.md file from Day 1.
Prompt to send to Gemini 3.5 Flash
Please check git status to verify modified changes. Stage only the modified 'test_case.md' requirements file using git add, then verify it has been staged successfully.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
I will locate modified changes and stage test_case.md.

**Step 1 β€” Verify modified files**
```bash
$ git status
On branch qe/feature-login-tests
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   test_case.md

no changes added to commit (use "git add" and/or "git commit -a")
```

**Step 2 β€” Stage test_case.md**
```bash
$ git add test_case.md
```

**Step 3 β€” Verify staging status**
```bash
$ git status
On branch qe/feature-login-tests
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   test_case.md
```

βœ… Successfully staged the modified 'test_case.md'. No other files have been modified or staged.
QE Observation
Make sure no unrelated configurations, environment keys, or production configuration files are listed in the staging area.
Phase 4

State Preservation & Verification

Preserve the work state by committing. The commit history acts as your rollback ledger. If the agent fails a future code iteration, you can instantly revert to this clean commit.

Instruct Agent
Send the prompt below to commit the changes and review the git logs.
Prompt to send to Gemini 3.5 Flash
Please commit the staged changes with the message "docs: update login test requirements for sandbox scoping". After committing, display the latest commit log details.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Staging is verified. I'll preserve this state.

**Step 1 β€” Commit staged changes**
```bash
$ git commit -m "docs: update login test requirements for sandbox scoping"
[qe/feature-login-tests ed38a5b] docs: update login test requirements for sandbox scoping
 1 file changed, 5 insertions(+), 2 deletions(-)
```

**Step 2 β€” Show latest commit**
```bash
$ git log -n 1
commit ed38a5bd1634b8c6f1a8c91d84b5cc223a54b9f2 (HEAD -> qe/feature-login-tests)
Author: Agentic QE <qe-orchestrator@shieldmutual.co.uk>
Date:   Wed Jul 1 18:44:00 2026 +0100

    docs: update login test requirements for sandbox scoping
```

βœ… Commit successfully saved. Ready for further tasks.
QE Observation
Ensure the commit message matches standard formats (e.g., prefixing with docs/feat/fix). Use the correction prompt if the message is messy.
Correction prompt (use if commit message is wrong)
The commit message you wrote does not follow our repository standards. 
Please amend the commit message to be precisely: docs: update login test requirements for sandbox scoping
To do this, run: git commit --amend -m "docs: update login test requirements for sandbox scoping"
Final sync prompt
Please run git status to ensure our working directory is clean, and git branch to confirm the active branch name.
πŸ“‹ Sample Agent Response for Verification β€” Gemini 3.5 Flash
Running final verification checks:

**Step 1 β€” git status**
```bash
$ git status
On branch qe/feature-login-tests
nothing to commit, working tree clean
```

**Step 2 β€” git branch**
```bash
$ git branch
  main
* qe/feature-login-tests
```

βœ… Verification complete. The working tree is clean and our state is preserved on 'qe/feature-login-tests'.
βœ… Lab Complete β€” Sandbox Switched & Preserved

The isolation checkpoint is complete. You have successfully switch Git branches, staged only targeted files, committed them, and audited logs. Should the agent fail at code editing or testing, you can roll back to ed38a5b immediately.

πŸŽ“ Day 2 Quick Check

Why is Git branch isolation and directory sandboxing critical for agent safety?