Skip to content

Call GitHub from a sandbox

Call the GitHub API from a sandbox with no token inside it.

This program creates a sandbox with the GitHub integration attached, calls the GitHub API from inside it and prints the result. No GitHub token is in the program or the sandbox.

import { AnchorClient } from "@mistrive/anchor";

const client = new AnchorClient({
  baseUrl: "https://anchor.jgcp.mistrivedev.com",
  token: process.env.SUTRA_API_KEY,
  project: process.env.SUTRA_PROJECT,
});

const sandbox = await client.create({
  sandbox: {
    maxDuration: "120s",
    resources: {
      $typeName: "anchor.types.v1.ResourceAllocation",
      vcpus: 1,
      memoryMb: BigInt(1024),
      diskMb: BigInt(1024),
    },
  },
  integrations: [{ providerKey: "github-legacy", scopes: ["read:user"] }],
});

// No token in the sandbox. The platform adds credentials outside the VM.
const result = await sandbox.exec({
  command: "curl",
  args: ["-sS", "https://api.github.com/user"],
});
console.log(result.stdout);

await sandbox.delete();
import os

from mistrive_anchor import AnchorClient

client = AnchorClient(
    base_url="https://anchor.jgcp.mistrivedev.com",
    token=os.environ["SUTRA_API_KEY"],
    project=os.environ["SUTRA_PROJECT"],
)

sandbox = client.create(
    {
        "sandbox": {
            "maxDuration": "120s",
            "resources": {"vcpus": 1, "memoryMb": 1024, "diskMb": 1024},
        },
        "integrations": [
            {"providerKey": "github-legacy", "scopes": ["read:user"]},
        ],
    }
)

# No token in the sandbox. The platform adds credentials outside the VM.
result = sandbox.exec({"command": "curl", "args": ["-sS", "https://api.github.com/user"]})
print(result.stdout)

sandbox.delete()

Not available yet.

import { Sutra } from "@mistrive/sutra";

const sutra = new Sutra({
  baseUrl: "https://anchor.jgcp.mistrivedev.com",
});

const sandbox = await sutra.sandboxes.create({
  resources: { milliCpus: 1000, memoryBytes: 1024 ** 3, diskBytes: 1024 ** 3 },
  lifecycle: { timeout: { seconds: 120, action: "DELETE" } },
  integrations: [{ provider: "github" }],
});

// No token in the sandbox. The platform adds credentials outside the VM.
const result = await sandbox.processes.run({
  argv: ["curl", "-sS", "https://api.github.com/user"],
});
console.log(result.stdout);

await sandbox.delete();
from mistrive.sutra import Sutra

sutra = Sutra(
    base_url="https://anchor.jgcp.mistrivedev.com",
)

sandbox = sutra.sandboxes.create(
    resources={"milli_cpus": 1000, "memory_bytes": 1024**3, "disk_bytes": 1024**3},
    lifecycle={"timeout": {"seconds": 120, "action": "DELETE"}},
    integrations=[{"provider": "github"}],
)

result = sandbox.processes.run(argv=["curl", "-sS", "https://api.github.com/user"])
print(result.stdout)

sandbox.delete()
#!/usr/bin/env bash
set -euo pipefail

# Assumes you ran `sutra auth login` (see the Quickstart).
sutra sandboxes create gh --timeout 120s --integration github
sutra processes run gh -- curl -sS https://api.github.com/user
sutra sandboxes delete gh

How it works

  1. The program creates a sandbox and attaches the GitHub integration.
  2. A process in the sandbox calls https://api.github.com/user with curl and no Authorization header.
  3. Sutra adds your organization’s GitHub credential to the request after it leaves the VM, and GitHub answers as usual.
  4. The program prints the response and deletes the sandbox.

Why no token is needed

The credential never enters the sandbox. Code you run there, including code an agent writes, can call GitHub but cannot read the token, print it or send it anywhere else. When you remove the integration or your organization revokes it, the sandbox loses access at once.

See Integrations and tool gateway for scopes and the tool gateway, and Supported integrations for the other providers you can call the same way.

Type to search…

↑↓ navigate↵ selectEsc close