Get StartedTutorials

Grant GitHub Push Access to a Sandboxed Agent

View as Markdown

This tutorial walks through an iterative sandbox policy workflow. You launch a sandbox, ask Claude Code to push code to GitHub, and observe the default network policy denying the request. You then diagnose the denial from your machine and from inside the sandbox, apply a policy update, and verify that the policy update to the sandbox takes effect.

After completing this tutorial, you will have:

  • A running sandbox with Claude Code that can push to a GitHub repository.
  • A custom network policy that grants GitHub access for a specific repository.
  • Experience with the policy iteration workflow: fail, diagnose, update, verify.

This tutorial shows example prompts and responses from Claude Code. The exact wording you see might vary between sessions. Use the examples as a guide for the type of interaction, not as expected output.

Prerequisites

This tutorial requires the following:

  • A working OpenShell installation. Complete the Quickstart before proceeding.
  • A GitHub personal access token (PAT) with repo scope. Generate one from the GitHub personal access token settings page by selecting Generate new token (classic) and enabling the repo scope.
  • An Anthropic account with access to Claude Code. OpenShell provides the sandbox runtime, not the agent. You must authenticate with your own account.
  • A GitHub repository you own to use as the push target. A scratch repository is sufficient. You can create one with a README if needed.

This tutorial uses two terminals to demonstrate the iterative policy workflow:

  • Terminal 1: The sandbox terminal. You create the sandbox in this terminal by running openshell sandbox create and interact with Claude Code inside it.
  • Terminal 2: A terminal outside the sandbox on your machine. You use this terminal for viewing the sandbox logs with openshell term and applying an updated policy with openshell policy set.

Each section below indicates which terminal to use.

1

Set Up a Sandbox with Your GitHub Token

Depending on whether you start a new sandbox or use an existing sandbox, choose the appropriate tab and follow the instructions.

In terminal 2, create a new sandbox with Claude Code. The default policy is applied automatically, which allows read-only access to GitHub.

Create a credential provider that injects your GitHub token into the sandbox automatically. The provider reads GITHUB_TOKEN from your host environment and sets it as an environment variable inside the sandbox:

$GITHUB_TOKEN=<your-token>
$openshell provider create --name my-github --type github --from-existing
$openshell sandbox create --provider my-github -- claude

openshell sandbox create keeps the sandbox running after Claude Code exits, so you can apply policy updates later without recreating the environment. Add --no-keep if you want the sandbox deleted automatically instead.

Claude Code starts inside the sandbox. It prints an authentication link. Open it in your browser, sign in to your Anthropic account, and return to the terminal. When prompted, trust the /sandbox workspace to allow Claude Code to read and write files.

2

Push Code to GitHub

In terminal 1, ask Claude Code to write a simple script and push it to your repository. Replace <org> with your GitHub organization or username and <repo> with your repository name.

Prompt
Write a `hello_world.py` script and push it to `https://github.com/<org>/<repo>`.

Claude recognizes that it needs GitHub credentials. It asks how you want to authenticate. Provide your GitHub personal access token by pasting it into the conversation. Claude configures authentication and attempts the push.

The push fails. Claude reports an error, but the failure is not an authentication problem. The default sandbox policy permits read-only access to GitHub and blocks write operations, so the proxy denies the push before the request reaches the GitHub server.

3

Diagnose the Denial

In this section, you diagnose the denial from your machine and from inside the sandbox.

View the Logs from Your Machine

In terminal 2, launch the OpenShell terminal:

$openshell term

The dashboard shows sandbox status and a live stream of policy decisions. Look for entries with l7_decision=deny. Select a deny entry to see the full detail:

l7_action: PUT
l7_target: /repos/<org>/<repo>/contents/hello_world.py
l7_decision: deny
dst_host: api.github.com
dst_port: 443
l7_protocol: rest
policy: github_rest_api
l7_deny_reason: PUT /repos/<org>/<repo>/contents/hello_world.py not permitted by policy

The log shows that the sandbox proxy intercepted an outbound PUT request to api.github.com and denied it. The github_rest_api policy allows read operations (GET) but blocks write operations (PUT, POST, DELETE) to the GitHub API. A similar denial appears for github.com if Claude attempted a git push over HTTPS.

Ask Claude Code to Check the Sandbox Logs

In terminal 1, ask Claude Code to check the sandbox logs for denied requests:

Prompt
Check the sandbox logs for any denied network requests. What is blocking the push?

Claude reads the deny entries and identifies the root cause. It explains that the failure is a sandbox network policy restriction, not a token permissions issue. For example, the following is a possible response:

Response

The sandbox runs a proxy that enforces policies on outbound traffic. The github_rest_api policy allows GET requests (used to read the file) but blocks PUT/write requests to GitHub. This is a sandbox-level restriction, not a token issue. No matter what token you provide, pushes through the API will be blocked until the policy is updated.

Both perspectives confirm the same thing: the proxy is doing its job. The default policy is designed to be restrictive. To allow GitHub pushes, you need to update the network policy.

Copy the deny reason from Claude’s response. You paste it into an agent running on your machine in the next step.

4

Update the Policy from Your Machine

In terminal 2, paste the deny reason from the previous step into your coding agent on your machine, such as Claude Code or Cursor, and ask it to recommend a policy update. The deny reason gives the agent the context it needs to generate the correct policy rules. After pasting the following prompt sample, properly provide the GitHub organization and repository names of the repository you are pushing to.

Prompt
Based on the following deny reasons, recommend a sandbox policy update that allows GitHub pushes to `https://github.com/<org>/<repo>`, and save to `/tmp/sandbox-policy-update.yaml`:
The `filesystem_policy`, `landlock`, and `process` sections are static. They are read once at sandbox creation and cannot be changed by a hot-reload. They are included here for completeness so the file is self-contained, but only the `network_policies` section takes effect when you apply this to a running sandbox.

The following steps outline the expected process done by the agent:

  1. Inspects the deny reasons.
  2. Writes an updated policy that adds github_git and github_api blocks that grant write access to your repository.
  3. Saves the policy to /tmp/sandbox-policy-update.yaml.
5

Review the Generated Policy

Refer to the following policy example to compare with the generated policy before applying it. Confirm that the policy grants only the access you expect. In this case, git push operations and GitHub REST API access scoped to a single repository.

The following YAML shows a complete policy that extends the default policy with GitHub access for a single repository. Replace <org> with your GitHub organization or username and <repo> with your repository name.

The filesystem_policy, landlock, and process sections are static. They are read once at sandbox creation and cannot be changed by a hot-reload. They are included here for completeness so the file is self-contained, but only the network_policies section takes effect when you apply this to a running sandbox.

1version: 1
2
3# ── Static (locked at sandbox creation) ──────────────────────────
4
5filesystem_policy:
6 include_workdir: true
7 read_only:
8 - /usr
9 - /lib
10 - /proc
11 - /dev/urandom
12 - /app
13 - /etc
14 - /var/log
15 read_write:
16 - /sandbox
17 - /tmp
18 - /dev/null
19
20landlock:
21 compatibility: best_effort
22
23process:
24 run_as_user: sandbox
25 run_as_group: sandbox
26
27# ── Dynamic (hot-reloadable) ─────────────────────────────────────
28
29network_policies:
30
31 # Claude Code ↔ Anthropic API
32 claude_code:
33 name: claude-code
34 endpoints:
35 - { host: api.anthropic.com, port: 443, protocol: rest, enforcement: enforce, access: full }
36 - { host: statsig.anthropic.com, port: 443 }
37 - { host: sentry.io, port: 443 }
38 - { host: raw.githubusercontent.com, port: 443 }
39 - { host: platform.claude.com, port: 443 }
40 binaries:
41 - { path: /usr/local/bin/claude }
42 - { path: /usr/bin/node }
43
44 # NVIDIA inference endpoint
45 nvidia_inference:
46 name: nvidia-inference
47 endpoints:
48 - { host: integrate.api.nvidia.com, port: 443 }
49 binaries:
50 - { path: /usr/bin/curl }
51 - { path: /bin/bash }
52 - { path: /usr/local/bin/opencode }
53
54 # ── GitHub: git operations (clone, fetch, push) ──────────────
55
56 github_git:
57 name: github-git
58 endpoints:
59 - host: github.com
60 port: 443
61 protocol: rest
62 enforcement: enforce
63 rules:
64 - allow:
65 method: GET
66 path: "/<org>/<repo>.git/info/refs*"
67 - allow:
68 method: POST
69 path: "/<org>/<repo>.git/git-upload-pack"
70 - allow:
71 method: POST
72 path: "/<org>/<repo>.git/git-receive-pack"
73 binaries:
74 - { path: /usr/bin/git }
75
76 # ── GitHub: REST API ─────────────────────────────────────────
77
78 github_api:
79 name: github-api
80 endpoints:
81 - host: api.github.com
82 port: 443
83 protocol: rest
84 enforcement: enforce
85 rules:
86 # GraphQL API (used by gh CLI)
87 - allow:
88 method: POST
89 path: "/graphql"
90 # Full read-write access to the repository
91 - allow:
92 method: "*"
93 path: "/repos/<org>/<repo>/**"
94 binaries:
95 - { path: /usr/local/bin/claude }
96 - { path: /usr/local/bin/opencode }
97 - { path: /usr/bin/gh }
98 - { path: /usr/bin/curl }
99
100 # ── Package managers ─────────────────────────────────────────
101
102 pypi:
103 name: pypi
104 endpoints:
105 - { host: pypi.org, port: 443 }
106 - { host: files.pythonhosted.org, port: 443 }
107 - { host: github.com, port: 443 }
108 - { host: objects.githubusercontent.com, port: 443 }
109 - { host: api.github.com, port: 443 }
110 - { host: downloads.python.org, port: 443 }
111 binaries:
112 - { path: /sandbox/.venv/bin/python }
113 - { path: /sandbox/.venv/bin/python3 }
114 - { path: /sandbox/.venv/bin/pip }
115 - { path: "/sandbox/.uv/python/**/python*" }
116 - { path: /usr/local/bin/uv }
117 - { path: "/sandbox/.uv/python/**" }
118
119 # ── VS Code Remote ──────────────────────────────────────────
120
121 vscode:
122 name: vscode
123 endpoints:
124 - { host: update.code.visualstudio.com, port: 443 }
125 - { host: "*.vo.msecnd.net", port: 443 }
126 - { host: vscode.download.prss.microsoft.com, port: 443 }
127 - { host: marketplace.visualstudio.com, port: 443 }
128 - { host: "*.gallerycdn.vsassets.io", port: 443 }
129 binaries:
130 - { path: /usr/bin/curl }
131 - { path: /usr/bin/wget }
132 - { path: "/sandbox/.vscode-server/**" }
133 - { path: "/sandbox/.vscode-remote-containers/**" }

The following table summarizes the two GitHub-specific blocks:

BlockEndpointBehavior
github_gitgithub.com:443Git Smart HTTP protocol. The proxy auto-detects and terminates TLS to inspect requests. Permits info/refs (clone/fetch), git-upload-pack (fetch data), and git-receive-pack (push) for the specified repository. Denies all operations on unlisted repositories.
github_apiapi.github.com:443REST API. The proxy auto-detects and terminates TLS to inspect requests. Permits all HTTP methods for the specified repository and GraphQL queries. Denies API access to unlisted repositories.

The remaining blocks (claude_code, nvidia_inference, pypi, vscode) are identical to the default policy. The default policy’s github_ssh_over_https and github_rest_api blocks are replaced by the github_git and github_api blocks above, which grant write access to the specified repository. Sandbox behavior outside of GitHub operations is unchanged.

For details on policy block structure, refer to Policies.

6

Apply the Policy

After you have reviewed the generated policy, apply it to the running sandbox:

$openshell policy set <sandbox-name> --policy /tmp/sandbox-policy-update.yaml --wait

Network policies are hot-reloadable. The --wait flag blocks until the policy engine confirms the new revision loaded, and the update takes effect immediately without restarting the sandbox or reconnecting Claude Code.

7

Retry the Push

In terminal 1, ask Claude Code to retry the push:

Prompt
The sandbox policy has been updated. Try pushing to the repository again.

The push completes successfully. The openshell term dashboard now shows l7_decision=allow entries for api.github.com and github.com where it previously showed denials.

8

Clean Up

When you are finished, delete the sandbox to free cluster resources:

$openshell sandbox delete <sandbox-name>

Next Steps

The following resources cover related topics in greater depth:

  • To add per-repository access levels (read-write vs read-only) or restrict to specific API methods, refer to the Policy Schema Reference.
  • To learn the full policy iteration workflow (pull, edit, push, verify), refer to Policies.
  • To inject credentials automatically instead of pasting tokens, refer to [Manage Providers](/sandboxes/manage-providers