Overview

Git in a sandbox

The sandbox.git module is deprecated

E2B's changelog of August 31, 2026 deprecates the sandbox git module in favour of running git through commands.run. Existing calls such as sandbox.git.clone() still appear in older examples; new code should use the pattern below.

Clone with a token#

Pass the token as an environment variable instead of writing it into the shell string or the repo's config.

import { Sandbox } from 'e2b'
 
const sandbox = await Sandbox.create({ timeoutMs: 600_000 })
 
await sandbox.commands.run(
  'git clone --depth 1 "https://x-access-token:${GITHUB_TOKEN}@github.com/your-org/your-repo.git" /home/user/repo',
  { envs: { GITHUB_TOKEN: process.env.GITHUB_TOKEN! } }
)
import os
from e2b import Sandbox
 
sandbox = Sandbox.create(timeout=600)
 
sandbox.commands.run(
    'git clone --depth 1 "https://x-access-token:${GITHUB_TOKEN}@github.com/your-org/your-repo.git" /home/user/repo',
    envs={"GITHUB_TOKEN": os.environ["GITHUB_TOKEN"]},
)

Branch, commit, read the diff#

const repo = 'cd /home/user/repo && '
 
await sandbox.commands.run(repo + 'git config user.name "E2B Bot" && git config user.email "bot@example.com"')
await sandbox.commands.run(repo + 'git checkout -b feature/agent-change')
 
// ... let the agent work ...
 
const diff = await sandbox.commands.run(repo + 'git diff')
console.log(diff.stdout)
 
await sandbox.commands.run(repo + 'git add -A && git commit -m "Agent change"')
repo = "cd /home/user/repo && "
 
sandbox.commands.run(repo + 'git config user.name "E2B Bot" && git config user.email "bot@example.com"')
sandbox.commands.run(repo + "git checkout -b feature/agent-change")
 
# ... let the agent work ...
 
diff = sandbox.commands.run(repo + "git diff")
print(diff.stdout)
 
sandbox.commands.run(repo + 'git add -A && git commit -m "Agent change"')

Anything stored on the sandbox disk — a credential helper, a token in .git/config — is readable by every process in the sandbox, including the agent. For credentials the sandbox should never see, look at Secrets.

Next#

Updated

Was this page helpful?