Use the sandbox.git helper to run common git operations inside a sandbox. The helper is non-interactive, so pass credentials explicitly or store them.
Git is available in the default sandbox template. If you’re using a custom or minimal template without git, install it first. See the install custom packages guide or add git in your template definition.
All examples below assume you already created a sandbox instance.
For private repos over HTTP(S), pass username and password (token) to the command that needs it. A username is required whenever you pass a password/token.
If you want to avoid passing credentials on each command, you can store them in the git credential helper inside the sandbox.
dangerouslyAuthenticate() / dangerously_authenticate() stores credentials on disk inside the sandbox. Any process or agent with access to the sandbox can read them. Use only when you understand the risk.
Copy
Ask AI
await sandbox.git.dangerouslyAuthenticate({ username: process.env.GIT_USERNAME, password: process.env.GIT_TOKEN, host: 'git.example.com', protocol: 'https',})// After this, HTTPS git operations can use the stored credentials.await sandbox.git.clone('https://git.example.com/org/private-repo.git', { path: '/workspace/repo',})await sandbox.git.push('/workspace/repo', { remote: 'origin', branch: 'main' })
If you intentionally want to keep credentials in the cloned repository, set the dangerouslyStoreCredentials / dangerously_store_credentials flag.
Storing credentials in the repository remote persists them in the repo config. Any process or agent with access to the sandbox can read them. Only use this when required.