Skip to content

Git

sandbox.git runs git in the sandbox with typed results: status, log, diff, branches and remotes come back as data, not as text to parse.

from svm import Sandbox
with Sandbox.create(template="base") as sandbox:
git = sandbox.git
repo = git.clone("https://github.com/octocat/Hello-World.git", "/tmp/hello", depth=1)
git.configure_user("Docs Bot", "[email protected]")
git.create_branch(repo, "docs-change")
sandbox.files.write(f"{repo}/NOTES.md", "Edited in an SVM sandbox.\n")
git.add(repo)
commit_id = git.commit(repo, "Add notes")
print("committed", commit_id)
status = git.status(repo)
print(status.branch, "clean" if status.clean else status.files)
for commit in git.log(repo, limit=3):
print(commit.id[:8], commit.subject, "-", commit.author_name)

For a private repository, use one of these. The token never enters the sandbox:

  • Create the sandbox with git credentials, then call install_credentials. A credential helper then answers through the platform.
  • Or bind a token to the host with an egress inject rule (Secrets). egress_env gives the environment that tells git to use it.