import uuid
from gravixlayer import GravixLayer
client = GravixLayer() # defaults to cloud="aws", region="us-east-1"
policy = client.network_policies.create(
name=f"git-github-{uuid.uuid4().hex[:8]}",
egress_mode="allowlist",
rules=[{"destination": "github.com", "port": 443, "protocol": "tcp"}],
)
sandbox = client.runtime.create(network_policy_ids=[policy.id]) # defaults to template="base-small"
sandbox.git.clone(
url="https://github.com/octocat/Hello-World.git",
path="/workspace/repo",
)
sandbox.git.create_branch("/workspace/repo", "tmp-branch")
sandbox.git.checkout("/workspace/repo", "master")
r = sandbox.git.delete_branch("/workspace/repo", "tmp-branch")
print(r.success, r.exit_code)
# Force delete: sandbox.git.delete_branch("/workspace/repo", "name", force=True)
sandbox.kill()
client.network_policies.delete(policy.id)