import os
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"
token = os.environ["GIT_TOKEN"]
sandbox.git.clone(
url="https://github.com/octocat/Hello-World.git",
path="/workspace/repo",
auth_token=token,
)
r = sandbox.git.push("/workspace/repo", remote="origin", auth_token=token)
print(r.success, r.stderr or r.stdout)
sandbox.kill()
client.network_policies.delete(policy.id)