The problem

If you run an AI coding agent in a sandbox, there's one thing that's easy to overlook: the agent's own login token. When you type /login in your coding agent from inside the sandbox, the OAuth token ends up stored in the sandbox. That means that if the agent gets manipulated by a prompt injection, it can read that token and exfiltrate it to an attacker-controlled website.

nono has a nice solution to this problem called sandboxed OAuth logins. In this post, I'll show how to set it up for GitHub Copilot CLI and a Business plan (not with an invididual subscription).

It's credential injection but in reverse

Regular credential injection works in one direction. You already have a secret, say an API key. You put a placeholder in the sandbox and the proxy swaps it for the real secret on outgoing requests. The secret is scoped to the hosts it's meant for: if a prompt-injected agent sends the placeholder to attacker.com, the proxy blocks it.

Regular credential injection: the proxy swaps the placeholder for the real token on a request to the approved host, and blocks the request when the agent is manipulated into sending it to attacker.com SANDBOX OUTSIDE THE SANDBOX 1. Request to the approved host Agent has a placeholder Proxy token is only valid for api.github.com api.github.com approved host placeholder real token 2. Prompt-injected request Agent prompt injected Proxy attacker.com is not approved for it attacker.com never gets anything placeholder ✕blocked The real token never enters the sandbox, and it's only ever sent to hosts approved for it. A placeholder sent anywhere else is useless to an attacker. gho_deadbeef gho_9f3a1c… gho_deadbeef

This doesn't help for /login, because the secret doesn't exist yet. The OAuth provider creates it during the login and sends it back in a response, straight into the sandbox.

nono also handles that direction. Its proxy watches the responses of the login endpoints and captures the real tokens as they come back. The agent only receives placeholders. From then on it's regular credential injection: the proxy swaps the placeholder for the real token, but only on requests to approved hosts.

Sandboxed OAuth login: the proxy captures the real tokens during login, the agent only gets placeholders, and the proxy swaps them back on later API calls SANDBOX OUTSIDE THE SANDBOX 1. Login (once) Agent you type: > /login Proxy intercepts the token response OAuth provider issues real access and refresh tokens OAuth capture store real tokens kept here real tokens placeholders 2. Later API calls Agent only knows placeholder tokens Proxy swaps placeholder for the real token API host gets the real token placeholder real token The agent can log in normally, but real tokens never enter the sandbox. A placeholder is useless if it is sent anywhere other than through the proxy. /login /login gho_9f3a1c… gho_deadbeef gho_deadbeef gho_9f3a1c…

Why it's so convenient

This is super useful to get started with a sandboxed agent. Without it, you have a few subpar options:

  • Log in inside the sandbox and leave the token there, where a manipulated agent can read it.
  • Log in outside the sandbox and copy the token into the sandbox, which exposes it just the same.
  • Log in outside the sandbox and set up regular credential injection manually with the token you got. This is safe, but it's a hassle, and you have to redo it when the token changes.

With nono, you start the agent in the sandbox, type /login like you normally would, and that's it.

Very few sandboxing tools support this. In my comparison, only nono and Docker Sandboxes did, and I only tested it with nono.

The profile

This setup is for GitHub Copilot CLI with an enterprise account on a dedicated GitHub Enterprise Cloud instance at example.ghe.com (replace it with your own domain).

Note that Copilot CLI must be installed on the host first. That's just how nono works: it uses OS-level sandboxing (Landlock on Linux, Seatbelt on macOS) to restrict a process running on your machine. Tools that run the agent in a microVM from an OCI image, like Docker Sandboxes, ship the agent inside the image, so there's nothing else to install on the host.

Here's the profile I used, saved as ~/.config/nono/profiles/copilot-custom.json:

{
  "extends": null,
  "meta": {
    "name": "copilot-custom",
    "version": "1.0.0",
    "description": "Copilot CLI profile with example.ghe.com /login support"
  },
  "network": {
    "block": false,
    "allow_domain": [
      "example.ghe.com",
      "copilot-api.example.ghe.com",
      "api.github.com",
      "api.githubcopilot.com"
    ]
  },
  "credential_providers": {
    "github_copilot_ghe": {
      "type": "oauth_capture",
      "token_endpoints": [
        {
          "host": "https://example.ghe.com",
          "path": "/login/device/code",
          "response_fields": [
            { "path": "access_token", "kind": "opaque" },
            { "path": "refresh_token", "kind": "opaque" },
            { "path": "id_token", "kind": "opaque" }
          ],
          "request_body": "auto",
          "request_nonce_fields": ["refresh_token"]
        },
        {
          "host": "https://example.ghe.com",
          "path": "/login/oauth/access_token",
          "response_fields": [
            {
              "path": "access_token",
              "kind": "opaque",
              "format": "gho_deadbeef{}"
            },
            { "path": "refresh_token", "kind": "opaque" }
          ],
          "request_body": "auto",
          "request_nonce_fields": ["refresh_token"]
        }
      ],
      "api_hosts": [
        "https://api.example.ghe.com",
        "https://copilot-api.example.ghe.com"
      ],
      "inject_header": null,
      "credential_format": null,
      "credential_store": {
        "type": "file_json",
        "path": "~/.github-copilot-ghe/auth.json",
        "phantom_fields": ["tokens.access_token", "tokens.refresh_token"]
      },
      "helpers": null
    }
  },
  "credential_routes": [
    {
      "name": "github_copilot_ghe_oauth",
      "provider": "github_copilot_ghe",
      "env_var": null,
      "base_url_env_var": null,
      "endpoint_policy": null,
      "upgrades": []
    }
  ]
}

What it does

  • network.allow_domain only allows outgoing traffic to the GHE instance and the Copilot API hosts.
  • The oauth_capture provider watches the login endpoints. When the real access_token and refresh_token come back, nono keeps them outside the sandbox.
  • format is the placeholder the agent gets. Copilot CLI refuses tokens that don't start with gho_, so the placeholder must look like a valid one.
  • api_hosts are the only hosts where the placeholder gets replaced by the real token.

Running it

nono run --profile copilot-custom --allow-cwd -- copilot

--allow-cwd gives read/write access to the current directory only. Then run /login inside Copilot CLI and go through the device code flow as usual. If something gets blocked, nono suggests profile changes when you exit.