Connect to a sandbox over SSH to debug it, edit files or run tools by hand. Each sandbox has one SSH access resource. You ask it for a short-lived credential and connect with any SSH client.
import { readFileSync } from "node:fs";
import { homedir } from "node:os";
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();
// Today you register your own public key for the sandbox.
const publicKey = readFileSync(`${homedir()}/.ssh/id_ed25519.pub`, "utf8").trim();
const access = await client.openSandboxAccessBinding({
sandbox: sandbox.name,
ssh: { publicKeys: [publicKey] },
});
// Run this command to connect.
console.log(access.route?.command);import os
from pathlib import Path
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()
# Today you register your own public key for the sandbox.
public_key = (Path.home() / ".ssh" / "id_ed25519.pub").read_text().strip()
access = client.open_sandbox_access_binding(
{"sandbox": sandbox.name, "protocol": "SSH", "ssh": {"publicKeys": [public_key]}}
)
# Run this command to connect.
print(access.route.command)#!/usr/bin/env bash
set -euo pipefail
# Assumes you ran `anchor auth login` with a project (see the Quickstart).
# Today the id of a deleted sandbox cannot be used again, so pick a new one.
sandbox="demo-$(date +%s)"
anchor sandbox create --name "$sandbox"
# Registers your local SSH key for the sandbox and connects.
anchor sandbox ssh "$sandbox"import { writeFileSync } from "node:fs";
import { Sutra } from "@mistrive/sutra";
const sutra = new Sutra({
baseUrl: "https://anchor.jgcp.mistrivedev.com",
});
const sandbox = await sutra.sandboxes.create();
// A short-lived key pair for this sandbox.
const credential = await sandbox.sshAccess.issueCredential();
writeFileSync("sandbox_key", credential.privateKey, { mode: 0o600 });
console.log(`Valid until ${credential.expireTime.toISOString()}. Connect with:`);
console.log(
`ssh -i sandbox_key -p ${credential.port} ${credential.user}@${credential.host}`,
);import os
from mistrive.sutra import Sutra
sutra = Sutra(
base_url="https://anchor.jgcp.mistrivedev.com",
)
sandbox = sutra.sandboxes.create()
# A short-lived key pair for this sandbox.
credential = sandbox.ssh_access.issue_credential()
fd = os.open("sandbox_key", os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
with os.fdopen(fd, "w") as key_file:
key_file.write(credential.private_key)
print(f"Valid until {credential.expire_time.isoformat()}. Connect with:")
print(f"ssh -i sandbox_key -p {credential.port} {credential.user}@{credential.host}")#!/usr/bin/env bash
set -euo pipefail
# Assumes you ran `sutra auth login` (see the Quickstart).
sutra sandboxes create demo
# Issues a short-lived credential and connects.
sutra ssh demoCredentials
issueCredential returns a host, a port, a user and a private key. The key works only for that sandbox and expires at expireTime. Ask for a new credential when it expires.
Keep the private key out of source control and out of other sandboxes. Write it to a file that only you can read, as the sample does.
Use it with other tools
The credential works with any tool that speaks SSH, such as scp, rsync or your editor’s remote extension. Pass the key with -i and the port with -p (-P for scp).
In the CLI, sutra ssh issues a credential and starts ssh for you.