Git
Git endpoints let you clone repositories, inspect diffs and history, manage branches, stage files, commit, push, and pull inside a running sandbox.
Clone repository
Section titled “Clone repository”Clone a remote repository into the sandbox.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.clone( url="https://github.com/octocat/Hello-World.git", path="/workspace/repo", branch="main", username="x-access-token", password="<personal-access-token>",)
print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/clone`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ url: "https://github.com/octocat/Hello-World.git", path: "/workspace/repo", branch: "main", username: "x-access-token", // optional, for private repos password: "<personal-access-token>", // optional, for private repos}),})
const data = await res.json()console.log(data.output)Status
Section titled “Status”Get the current repository status as raw git status --porcelain=v2 --branch output.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.status(path="/workspace/repo")print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/status`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo" }),})
const data = await res.json()console.log(data.output)List branches
Section titled “List branches”List branches in the repository as raw git branch output.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.branches(path="/workspace/repo", branch_type="all")print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/branches`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", branch_type: "all" }),})
const data = await res.json()console.log(data.output)Diff unstaged
Section titled “Diff unstaged”Show working tree changes that are not staged yet.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.diff_unstaged(path="/workspace/repo", context_lines=5)print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/diff-unstaged`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", context_lines: 5 }),})
const data = await res.json()console.log(data.output)Diff staged
Section titled “Diff staged”Show changes that are already staged for the next commit.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.diff_staged(path="/workspace/repo", context_lines=5)print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/diff-staged`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", context_lines: 5 }),})
const data = await res.json()console.log(data.output)Diff target
Section titled “Diff target”Compare the current repository state against a branch, tag, or commit.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.diff(path="/workspace/repo", target="origin/main", context_lines=3)print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/diff`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", target: "origin/main", context_lines: 3 }),})
const data = await res.json()console.log(data.output)Reset staged changes
Section titled “Reset staged changes”Unstage all currently staged changes in the repository.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.reset(path="/workspace/repo")print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/reset`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo" }),})
const data = await res.json()console.log(data.output)Show commit history with optional limits and date filters.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.log(path="/workspace/repo", max_count=10)print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/log`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", max_count: 10 }),})
const data = await res.json()console.log(data.output)Show revision
Section titled “Show revision”Show the full output for a commit, branch, or tag revision.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.show(path="/workspace/repo", revision="HEAD~1")print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/show`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", revision: "HEAD~1" }),})
const data = await res.json()console.log(data.output)Create branch
Section titled “Create branch”Create a new branch. Set checkout to switch to it immediately, and optionally pass base_branch to branch from a specific revision.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.create_branch( path="/workspace/repo", name="feature/docs", checkout=True, base_branch="main",)
print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/create-branch`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", name: "feature/docs", checkout: true, base_branch: "main" }),})
console.log(res.status)Checkout branch
Section titled “Checkout branch”Switch to an existing branch.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.checkout_branch(path="/workspace/repo", branch="main")print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/checkout-branch`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", branch: "main" }),})
console.log(res.status)Delete branch
Section titled “Delete branch”Delete a branch. Set force to delete even if unmerged.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.delete_branch(path="/workspace/repo", name="feature/docs", force=True)print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/delete-branch`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", name: "feature/docs", force: true }),})
console.log(res.status)Add files
Section titled “Add files”Stage files for the next commit.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.add(path="/workspace/repo", files=["README.md"])print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/add`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", files: ["README.md"] }),})
console.log(res.status)Commit
Section titled “Commit”Create a commit from staged changes.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()commit = sandbox.git.commit( path="/workspace/repo", message="docs: update filesystem guide", author="Leap0 Bot", email="bot@example.com",)
print(commit.sha)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/commit`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", message: "docs: update filesystem guide", author: "Leap0 Bot", email: "bot@example.com",}),})
const data = await res.json()console.log(data.sha)Push commits to a remote.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.push( path="/workspace/repo", remote="origin", branch="main", set_upstream=True,)
print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/push`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", remote: "origin", branch: "main", set_upstream: true,}),})
console.log(res.status)Pull commits from a remote. Set rebase to rebase instead of merge. Set set_upstream to set upstream tracking for the branch.
from leap0 import Leap0Client
client = Leap0Client()sandbox = client.sandboxes.create()result = sandbox.git.pull( path="/workspace/repo", remote="origin", branch="main", rebase=True, set_upstream=True,)
print(result.output)const apiUrl = "https://api.leap0.dev"const apiKey = "<your-api-key>"const sandboxId = "<sandbox_id>"
const res = await fetch(`${apiUrl}/v1/sandbox/${sandboxId}/git/pull`, {method: "POST",headers: { authorization: apiKey, "Content-Type": "application/json",},body: JSON.stringify({ path: "/workspace/repo", remote: "origin", branch: "main", rebase: true, set_upstream: true,}),})
console.log(res.status)