Skip to main content
Clone a repository, inspect changes, commit work, push a branch, or open a pull request from inside a box.

Configure Git Access

If you want to work with private repositories, push changes, or create pull requests, create the box with a GitHub token.
For a fine-grained token, the following permissions are sufficient for basic usage:
  • Contents — Read and write
  • Pull requests — Read and write
.env
UPSTASH_BOX_API_KEY=abx_xxxxxxxxxxxxxxxxxxxxxxxx
GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxx
import { Box } from "@upstash/box"

const box = await Box.create({
  runtime: "node",
  git: {
    token: process.env.GITHUB_TOKEN,
  },
})

Git identity

You can also set the git author identity that will be used for commits made inside the box. Both fields are optional and applied to the container’s global git config on creation.
FieldTypeDefaultDescription
tokenstringGitHub token for private repos and push
userNamestring"Upstash Box"Value written to git config user.name
userEmailstring"box@upstash.com"Value written to git config user.email
import { Box } from "@upstash/box"

const box = await Box.create({
  runtime: "node",
  git: {
    token: process.env.GITHUB_TOKEN,
    userName: "deploy-bot",
    userEmail: "deploy-bot@acme.com",
  },
})
If userName or userEmail are omitted, the box uses the defaults ("Upstash Box" / "box@upstash.com"). Omitting token is fine for public repositories where push access is not required.

Quickstart

Clone a repository

await box.git.clone({
  repo: "https://github.com/acme/web-app",
  branch: "main",
})

await box.cd("web-app")

await box.git.exec({
  args: ["checkout", "-b", "fix/empty-state"],
})

Inspect what changed

Use status() for a compact summary and diff() to diff the repo’s uncommitted changes against the initial state.
const status = await box.git.status()
const diff = await box.git.diff()

console.log(status)
console.log(diff)

Commit and push

After your code changes are ready, create a commit and push the branch.
const commit = await box.git.commit({
  message: "fix: handle empty state in dashboard",
})

await box.git.push({ branch: "fix/empty-state" })

console.log(commit.sha)
console.log(commit.message)

Open a pull request

Create a PR once your branch is pushed.
const pr = await box.git.createPR({
  title: "fix: handle empty state in dashboard",
  body: "Improves the dashboard empty state and avoids a broken loading flow.",
  base: "main",
})

console.log(pr.url)

API

Clone

Clones a repository into the current working directory in the box.
await box.git.clone({
  repo: "https://github.com/acme/api",
})

// 👇 you can also select a branch during clone:
await box.git.clone({
  repo: "https://github.com/acme/api",
  branch: "develop",
})

Status

Returns the Git status output for the repository in the current working directory.
  • See what files changed
  • See if there are there untracked files
const status = await box.git.status()

Diff

Returns the current Git diff as a string.
  • Useful to display a patch in your UI
  • Review what an agent changed
const diff = await box.git.diff()

Commit

Creates a commit and returns commit information including the SHA and message.
const commit = await box.git.commit({
  message: "feat: add onboarding checklist",
})
You can optionally override the commit author for a single commit using authorName and authorEmail. When omitted, the box’s configured git identity is used (either the values set at creation via config.git or the latest updateConfig values).
const commit = await box.git.commit({
  message: "feat: add onboarding checklist",
  authorName: "Alice",
  authorEmail: "alice@acme.com",
})
OptionTypeRequiredDescription
messagestringYesCommit message
authorNamestringNoOverride --author name for this commit only
authorEmailstringNoOverride --author email for this commit only

Push

Pushes the current branch. You can also provide a branch name explicitly.
// 👇 push to default branch
await box.git.push()

// 👇 or to a specific branch
await box.git.push({
  branch: "feature/onboarding-checklist",
})

Create a PR

Creates a pull request and returns the PR URL and metadata.
const pr = await box.git.createPR({
  title: "feat: add onboarding checklist",
  body: "Adds a simple onboarding checklist to improve first-run guidance.",
  base: "main",
})

Checkout

Switches to another branch in the current repository.
await box.git.checkout({
  branch: "release/v1.2.0",
})

Run a custom Git command

Runs a raw Git command and returns the command output. Useful escape hatch if the built-in helpers don’t cover a use case.
const result = await box.git.exec({
  args: ["branch", "--show-current"],
})

Update Git Config

Updates the git author identity in the running container. At least one field must be provided; the other field retains its current value. Returns the effective identity values after the update.
const identity = await box.git.updateConfig({
  userName: "ci-bot",
  userEmail: "ci-bot@acme.com",
})

console.log(identity.git_user_name)  // "ci-bot"
console.log(identity.git_user_email) // "ci-bot@acme.com"
You can update a single field — the other will not change:
// Only update the email, keep the existing user name
const identity = await box.git.updateConfig({
  userEmail: "ci-bot@acme.com",
})
If the box is in Running or Idle state, the new config is applied immediately inside the container (equivalent to running git config --global for the updated fields). Changes take effect for all subsequent commits.
OptionTypeRequiredDescription
userNamestringNoNew value for user.name
userEmailstringNoNew value for user.email
Return value: { git_user_name: string; git_user_email: string }

Examples

Use Git with an agent

If you configured a box agent, it also has full git access. This is especially useful when the exact git steps are not known ahead of time. For example, if the user sends an open-ended request, you may not know in advance what branch name, commit message, or final push flow makes sense. In that case, you can let the agent inspect the repository, decide what changes are needed, and handle the git workflow itself.
import { Box, Agent, ClaudeCode } from "@upstash/box"

const box = await Box.create({
  runtime: "node",
  agent: {
    provider: Agent.ClaudeCode,
    model: ClaudeCode.Opus_4_6,
    apiKey: process.env.ANTHROPIC_API_KEY,
  },
  git: {
    token: process.env.GITHUB_TOKEN,
  },
})

await box.git.clone({
  repo: "https://github.com/acme/web-app",
  branch: "main",
})

await box.cd("web-app")

const run = await box.agent.run({
  prompt: `
Inspect this repository and fix the broken mobile navigation.

Create a branch with a sensible name, make the necessary code and test changes, commit the changes, then push the branch and open a pull request against main.`,
})

End-to-end PR automation

import { Box, Agent, ClaudeCode } from "@upstash/box"

const box = await Box.create({
  runtime: "node",
  agent: {
    provider: Agent.ClaudeCode,
    model: ClaudeCode.Opus_4_6,
    apiKey: process.env.ANTHROPIC_API_KEY,
  },
  git: {
    token: process.env.GITHUB_TOKEN,
  },
})

await box.git.clone({
  repo: "https://github.com/acme/docs-site",
  branch: "main",
})

await box.cd("docs-site")

await box.git.exec({
  args: ["checkout", "-b", "docs/deployment-troubleshooting"],
})

await box.agent.run({
  prompt: "Add a troubleshooting section to the deployment guide.",
})

await box.git.commit({
  message: "docs: add deployment troubleshooting section",
})

await box.git.push({ branch: "docs/deployment-troubleshooting" })

const pr = await box.git.createPR({
  title: "docs: add deployment troubleshooting section",
  base: "main",
})