Go SDK

sandal.dev/go (private beta): configuration from the environment, a Sandbox handle and iterator-based helpers, plus the low-level client for every endpoint.


Install#

Private beta: the module sandal.dev/go (Go 1.23+) is not on the Go proxy yet. Point it at the source from your beta bundle:

go mod edit -require=sandal.dev/go@v0.1.0-beta.16 -replace=sandal.dev/go=./sdk/go/sandal-go-v0.1.0-beta.16
go mod tidy

Create the client#

import (
	"context"
	"fmt"
	"log"

	sandal "sandal.dev/go"
)

client, err := sandal.NewSandalFromEnv(sandal.SandalEnvOptions{}) // SANDAL_API_KEY alone is enough, else the `sandal login` profile
if err != nil {
	log.Fatal(err)
}

// or explicitly (OrganizationID and ProjectID are optional overrides):
client, err = sandal.NewSandal(sandal.Target{
	BaseURL: "https://api.sandal.dev", APIToken: key, OrganizationID: org, ProjectID: project,
})

Every call takes a context.Context; cancelling it stops waits, retries and streams.

The short way#

sb, err := client.CreateSandbox(ctx, sandal.SandalCreateSandboxOptions{}) // default template, waits until running
if err != nil {
	log.Fatal(err)
}
defer sb.Delete(ctx, sandal.SandalLifecycleOptions{})
res, err := sb.Exec(ctx, sandal.ShellCommand("echo hi && uname -a"), nil)
fmt.Println(res.Status, res.Stdout)
_, err = sb.Push(ctx, "./app", "") // git-aware copy to /workspace/app

The handle, Exec / StreamCommand / RunCommand (iter.Seq2 frames), files of any size, Push, RunJob, Expose / Share, lifetime, usage, saved snapshots and history are documented once for all three languages on the SDK pages (TypeScript, Python, Go). The rest of this page is the low-level client: one method per endpoint.

Facade methods return (result, *http.Response, error). API failures unwrap to *sandal.SandalAPIError with errors.As (Code, Status, Reason, RequestID, RetryAfter, Retryable()); see Limits.

Conventions#

  • Idempotency. Mutations carry Identity: sandal.SandalMutationIdentity{IdempotencyKey: "…"}. A zero identity gets a random key, reused by retries.
  • Revisions. ExpectedSandboxRevision (exec, files, ports, snapshots) and ExpectedRevision (lifecycle inputs) are read for you when zero, with one retry on revision_conflict. The examples below pass them explicitly to show the wire contract.
  • Retries. SandalRetryPolicy (default 3): 429, 502, 503, 504 and network failures, honouring Retry-After.
  • Operations. Create, lifecycle and fork return a result with .Operation.Id; wait with client.Sandboxes.WaitForOperation.
func key() sandal.SandalMutationIdentity {
	b := make([]byte, 16)
	_, _ = rand.Read(b) // crypto/rand
	return sandal.SandalMutationIdentity{IdempotencyKey: fmt.Sprintf("%x", b)}
}

func revision(ctx context.Context, client *sandal.Sandal, id string) int32 {
	sandbox, _, err := client.Sandboxes.Get(ctx, id, "")
	if err != nil {
		log.Fatal(err)
	}
	return int32(sandbox.Revision)
}

func wait(ctx context.Context, client *sandal.Sandal, operationID string) error {
	_, _, err := client.Sandboxes.WaitForOperation(ctx, operationID,
		sandal.SandalOperationWaitOptions{Timeout: 5 * time.Minute, PollInterval: 500 * time.Millisecond})
	return err
}

Templates#

published, _, err := client.Builds.Templates.GetPublished(ctx, "<template-id>", "")
// published.TemplateDigest, published.Profile, published.Architecture

Template ids change when a template is rebuilt: sandal templates list shows the current ones, and omitting the template (the project default) never goes stale. Catalog ids are retired when the image is respun: a retired id answers 404 resource_not_found (“was retired… omit the template to use the project default”). Omit the template to always get the project's default; the templateId of any sandbox you create names the current one.

Sandboxes#

size, arch, name := sandal.SandboxSize("s"), sandal.SANDBOXCPUARCHITECTURE_AMD64, "agent-1"
created, _, err := client.Sandboxes.Create(ctx, sandal.SandalSandboxCreateInput{
	Kind:           sandal.SANDBOXKIND_VIRTUAL_MACHINE, // SANDBOXKIND_CONTAINER for the container template
	TemplateID:     "<template-id>",
	TemplateDigest: "sha256:f311884c8be75a75ada50405624aefff53ebc6611590b7cf9275fe16dc0dee6b",
	Size:           &size, // xs | s | m | l | xl
	Architecture:   &arch,
	Name:           &name,
	Lifecycle:      *sandal.NewSandboxLifecyclePolicyInput(time.Now().Add(time.Hour)), // hard expiry
	NetworkPolicy:  sandal.NewSandboxNetworkPolicyInput(false), // optional: block internet egress
	Identity:       key(),
})
if err != nil {
	log.Fatal(err)
}
if err := wait(ctx, client, created.Operation.Id); err != nil {
	log.Fatal(err)
}
id := created.Sandbox.Id

Lifecycle verbs share one input type:

input := sandal.SandalLifecycleMutationInput{ExpectedRevision: revision(ctx, client, id), Identity: key()}
stopped, _, err := client.Sandboxes.Stop(ctx, id, input) // also Start, Archive, Delete
// then: wait(ctx, client, stopped.Operation.Id)

recovered, _, err := client.Sandboxes.Recover(ctx, id, sandal.SandalRecoverInput{
	SandalLifecycleMutationInput: sandal.SandalLifecycleMutationInput{ExpectedRevision: revision(ctx, client, id), Identity: key()},
})

Archive needs a running sandbox. client.Sandboxes.List(ctx, sandal.SandalSandboxListInput{}) lists the project's sandboxes.

Processes#

started, _, err := client.Processes.Exec(ctx, id, sandal.SandalExecInput{
	Command:                 []string{"sh", "-c", "for i in 1 2 3; do echo tick $i; sleep 1; done; exit 3"},
	ExpectedSandboxRevision: revision(ctx, client, id),
	Identity:                key(),
})
if err != nil {
	log.Fatal(err)
}
_, err = client.Processes.StreamEvents(ctx, id, started.Process.Id,
	sandal.SandalProcessEventStreamOptions{Timeout: 2 * time.Minute},
	func(event sandal.SandboxProcessEvent) error {
		data, err := base64.StdEncoding.DecodeString(event.DataBase64)
		os.Stdout.Write(data)
		return err
	})

process, _, err := client.Processes.Get(ctx, id, started.Process.Id, "")
if process.ExitCode.IsSet() && process.ExitCode.Get() != nil {
	fmt.Println("exit code", *process.ExitCode.Get()) // 3 (poll Get briefly if not set yet)
}

A process keeps at most MaxOutputBytes of output (16 MiB by default, up to 64 MiB). When a command passes it, sb.Exec / ExecCommand return the output so far together with a *sandal.SandalCommandOutputLimitError (check with errors.As).

On a held handle, repeated sb.Exec calls take on the direct exec path about 125 ms median on the default Linux template and about 50 ms on the default container image (from Helsinki, November 29, 2026), and about 250 ms over the API path (one EU vantage point, November 2026). The SDK uses the direct path whenever the sandbox's image offers it (the default Linux template and the default container image do) and falls back to the API by itself. Since 0.1.0-beta.16 a handle keeps one direct-exec stream and runs each command as a channel of it (sandal.exec.v2, on by default), so only the first command pays the connection setup; turn it off with DirectExecMulti: &off or SANDAL_DIRECT_EXEC_MULTI=0 (also false, off, no). Where a host or image does not offer it (the default Linux template answers with v1 today), each command opens its own connection as before; a handle you get later (by id, or from a create that did not wait) finds the direct path on its first command. sandal.SandalCommandOptions{User: "root"} runs as root on templates that allow it (always over the API path); the default template refuses it with 422 capability_unavailable. See Root and FUSE (preview).

Files#

_, _, err = client.Files.Write(ctx, id, sandal.SandalFileWriteInput{
	Path:       "/workspace/hello.txt",
	DataBase64: base64.StdEncoding.EncodeToString([]byte("hello sandal\n")),
	Offset:     0, Truncate: true, CreateParents: true,
	ExpectedSandboxRevision: revision(ctx, client, id),
	Identity:                key(),
})

offset, limit := int64(0), int64(65536)
file, _, err := client.Files.Download(ctx, id, "/workspace/hello.txt",
	sandal.SandalFileReadInput{Offset: &offset, Limit: &limit})
data, _ := base64.StdEncoding.DecodeString(file.DataBase64)

One write carries at most 256 KiB. Large transfers use signed transfer URLs (24 MiB in about 5 s up and 3 s down); where those are switched off the SDK falls back to the much slower chunked API.

Ports#

exposed, _, err := client.Sandboxes.ExposePort(ctx, id, sandal.SandalPortExposureCreateInput{
	ExpectedSandboxRevision: revision(ctx, client, id),
	Port:                    8080,
	Protocol:                sandal.SANDBOXPORTEXPOSUREPROTOCOL_HTTP,
	TtlSeconds:              600,
	Identity:                key(),
})
exposure := &exposed.Exposure
for exposure.State != "ready" {
	time.Sleep(500 * time.Millisecond)
	exposure, _, err = client.Sandboxes.GetPortExposure(ctx, id, exposed.Exposure.Id, "")
}
url := *exposure.Url.Get() // requests need `Authorization: Bearer <API key>`

Snapshots and forks#

snap, _, err := client.Sandboxes.CreateSnapshot(ctx, id, sandal.SandalSnapshotCreateInput{
	ExpectedSandboxRevision: revision(ctx, client, id),
	Identity:                key(),
})
// poll client.Sandboxes.GetSnapshot(ctx, id, snap.Snapshot.Id, "") until State == "ready"

forkName := "agent-1-fork"
forked, _, err := client.Sandboxes.Fork(ctx, id, sandal.SandalForkInput{
	SandalLifecycleMutationInput: sandal.SandalLifecycleMutationInput{ExpectedRevision: revision(ctx, client, id), Identity: key()},
	Name:                         &forkName,
	Lifecycle:                    sandal.NewSandboxLifecyclePolicyInput(time.Now().Add(time.Hour)),
})
// then: wait(ctx, client, forked.Operation.Id); forked.Sandbox.Id is the new sandbox

Not yet available on the beta#

The SDK contains clients for a few parts of the API that the beta deployment does not offer yet: file watch, volume snapshots and telemetry export answer capability_unavailable today, the Xcode Builds client has no Mac hosts behind it yet, and the macOS client needs a Mac leased to your organisation. Auto-pause (autoResume), bring-your-own egress, browser sessions and template builds are enabled per project during the beta. The current state per feature is on Limits; sandal capabilities shows what your project can do.

Every facade: Sandboxes, Processes, Files, Git, Agents, Code, LanguageServers, Computer, Browsers, Devices, Builds, Events, Telemetry, Keys, Audit.