Work with Git
Git is installed in the default sandbox image.
mjs
import { Sandbox } from "@abox-dev/sdk";
const sandbox = await Sandbox.create();
const repo = "/home/user/project";
try {
await sandbox.commands.run(`git init --initial-branch=main ${repo}`);
await sandbox.commands.run(
'git config user.name "AgentBox User" && git config user.email "user@example.com"',
{ cwd: repo },
);
await sandbox.files.write(`${repo}/README.md`, "# AgentBox project\n");
await sandbox.commands.run(
"git add README.md && git commit -m 'Initial commit'",
{
cwd: repo,
},
);
const result = await sandbox.commands.run("git log -1 --oneline", {
cwd: repo,
});
console.log(result.stdout);
} finally {
await sandbox.kill();
}Set cwd to the repository directory for commands such as status, branch, pull, and push. You can also run git clone from its parent directory.
Private repositories require credentials from your Git provider. Pass short-lived credentials at runtime. Do not store access tokens in a template, sandbox metadata, or a remote URL committed to .git/config.