feat(sdk-go): add the Go SDK, go.daytona.com/sdk/v2

Merged
MD
12d ago
+78690-88

Adds the Go SDK for the 2.x line: one idiomatic Go package, daytona, published as the module go.daytona.com/sdk/v2. It implements the same 2.x contract as the Python and TypeScript SDKs: the same operations and wire requests, validation, error codes and wait semantics. It also wires the module into CI, the live e2e suite, the SDK publish workflow and the Firegoat AX evals.

Depends on #688 (serves the go.daytona.com/sdk go-import tag from main) and #687 (removes the old release/v0 copy of that site). Until #688 is deployed, go get go.daytona.com/sdk/v2 cannot resolve; nothing in this PR publishes anything.

What a user writes

import "go.daytona.com/sdk/v2" // package daytona

client, err := daytona.New() // reads DAYTONA_API_KEY
if err != nil { return err }
defer client.Close()

sandbox, err := client.Create(ctx, "", nil) // "" = the platform default image
if sandbox != nil { defer sandbox.Delete(ctx, nil) } // non-nil once the server accepted the create
if err != nil { return err }

res, err := sandbox.Exec(ctx, `python3 -c "print(6 * 7)"`, nil)
if err != nil { return err } // the call failed; a non-zero exit code is not an error
fmt.Println(res.Reason, res.Stdout) // res.ExitCode is a *int: nil when the process was signalled

err = sandbox.FS().UploadFile(ctx, "data.csv", "/workspace/data.csv", nil) // sandbox paths are absolute
endpoint, err := sandbox.Ports().Expose(ctx, 8080, &daytona.ExposePortOptions{Public: true})

// Build an image and boot a sandbox from it in one call (create options are checked before the billed build).
built, err := client.CreateFromBuild(ctx,
	daytona.NewImageBuilder("python:3.12-slim").PipInstall("six==1.17.0"),
	&daytona.CreateFromBuildOptions{BuildTimeout: 4 * time.Minute})

if errors.Is(err, daytona.ErrSandboxNotRunning) { … } // a specific code
if errors.Is(err, daytona.ErrNotFound) { … }          // a category

Go-specific choices, all deliberate:

ConcernPython / TypeScriptGo
Durationswait_seconds / waitSeconds numberstime.Duration everywhere; daytona.NoWait, daytona.WaitForever, daytona.NoTimeout sentinels
Optional argumentskeyword args / option bags*XxxOptions last, nil = all defaults
Cancellationtimeoutsctx context.Context first on every call; cancellation also stops waits
Errorsclass hierarchy*daytona.Error + errors.Is(err, daytona.ErrNotFound) (category) and errors.Is(err, daytona.ErrSandboxNotRunning) (code)
Listspages / async iteratorsList → *Page[T], ListAll → iter.Seq2[T, error]
Streams and filescallbacks, Blobs, pathsio.Reader / io.Writer, local paths, iter.Seq2 for event streams
v0 APIDaytona().v0 namespace bundled into 2.xnone: Go builds two major versions side by side, so v0 code keeps importing github.com/daytona/clients/sdk-go next to this module
Tracingbuilt-in OTel optionwrap the transport of daytona.WithHTTPClient (for example with otelhttp); no tracing dependency

Go-only additions, also deliberate: ExecArgs / StartArgs (an argv without a shell), io.Reader / io.Writer transfers, Images.BuildFromContextReader (a build context from a stream) and Images.BuildAndWait (submit a build and wait for the image, for callers who want the image rather than a sandbox). The create methods match the other SDKs one to one: Create, CreateFromSnapshot, CreateFromBuild, CreateMacOS, and Sandbox.Fork.

How the module is found, and why nobody on 0.x is moved by accident

flowchart LR
  dev["go get go.daytona.com/sdk/v2"] --> meta["go.daytona.com/sdk/v2?go-get=1<br/>go-import: go.daytona.com/sdk git github.com/daytona/clients <b>sdk-go</b>"]
  meta --> dir["daytona/clients<br/>directory sdk-go/ on main"]
  dir --> tag["tag sdk-go/v2.X.Y<br/>(same commit as v2.X.Y)"]
  tag --> proxy["proxy.golang.org<br/>go.daytona.com/sdk/v2@v2.X.Y"]
  old["0.x module github.com/daytona/clients/sdk-go<br/>release/v0, tags sdk-go/v0.X.Y"] -. "different module path:<br/>go get -u never crosses" .-> proxy
  • The /v2 path suffix is Go's major-version rule. go get -u, @latest and Dependabot never move a module across majors.
  • The 0.x module also reads sdk-go/* tags, but Go ignores v2+ for a path without a /v2 suffix. The publish workflow therefore refuses any Go version whose major is not the suffix in sdk-go/go.mod, so a sdk-go/v0.* or sdk-go/v1.* tag can never come from main.
  • The go-import tag uses the subdirectory field from Go 1.25, which keeps sdk-go out of the import path. I checked this end to end with Go 1.26.10 against a local repo holding both sdk-go/v0.x and sdk-go/v2.x tags: go get, go get <pkg>@v2.1.0, go mod tidy and go get -u all resolve.
  • A future major is a new path, go.daytona.com/sdk/v3, which users opt into by changing an import.

Releasing

sequenceDiagram
  participant M as maintainer
  participant G as gate + build-go (no tokens)
  participant P as publish job (release env)
  participant GH as daytona/clients
  participant X as proxy.golang.org
  M->>G: SDK Publish, version v2.X.Y, publish_go=true
  G->>G: major of v2.X.Y == /v2 in sdk-go/go.mod? tag absent (or same commit)?<br/>version not yet in the proxy's @v/list?
  G->>G: go mod verify, build, vet, test on the source snapshot
  M->>P: one approval (same as the other targets)
  P->>GH: create tag sdk-go/v2.X.Y at the source commit
  P->>X: poll @v/v2.X.Y.info until Version == v2.X.Y (up to 35 min)

There is nothing to upload and no follow-up commit: the tag is the release. No go.mod/go.sum sync PRs are needed, unlike release/v0, because the generated wire models are internal packages of the same module. The registry check reads the proxy's version list, never <version>.info, because the proxy caches a "not found" for up to 30 minutes. Once the proxy has a version it cannot be deleted, only retracted by a later release; docs/RELEASING.md covers this.

One-time setting (not done here): add refs/tags/sdk-go/v* to the Release tags ruleset.

Follow-ups outside this PR

  • The TypeScript hub discards a decisive early-probe read when a socket frame arrived during the GET (events.ts:1150-1153); the contract's client_rules.early_probe says a target or terminal read settles the waiter. Go follows the contract text; TypeScript (or the contract wording) should be aligned.
  • Right after a create, a sandbox read can still answer an earlier status (running, then assigned on the next read). The SDKs report what each read says; the live tests re-read until started.
  • GET /files/watch can end with an error envelope (contract: macOS access denials). No SDK maps it yet (TypeScript FileSystem.ts:647-655 skips it too), so a watch reports a generic connection error. Mapping it to its typed error should land in all SDKs together.

What is in the diff

AreaFiles
Module scaffold, wire modelssdk-go/go.mod, sdk-go/gen-contract.sh, sdk-go/internal/gen/{api,toolbox} (generated, 10.4k lines, oapi-codegen v2.8.0, same pin as the CLI)scripts/gen-contract-types.sh --check covers them
Coreclient*, options*, transport*, toolbox_transport*, auth* (API key, JWT → project token), errors*, codes* (catalog generated from the TS one by codes_generate.go), durations*, page*, sandbox* (handle, get/list/search)
Lifecyclesandbox_create*, create_*, sandbox_lifecycle*, sandbox_wait*, policies, labels, env, network policy, sandbox secrets, access tokens, metrics, macOSwaits are event-driven: the API is probed only after the socket has been silent for 10 s (client_rules.early_probe), plus one authoritative read at the end of the budget
Eventsevents*, internal/eventssandbox-state WebSocket hub per contract/sandbox-events-protocol.json
Toolboxfs*, transfer*, watch*, process*, exec*, pty*, session*, interpreter*, git*, ports*, docker*, sandbox_volumes*, computer_use*
Imagesimage*, images*, builder*, build_logs*, context_upload*, snapshot*, internal/dockerignore, internal/buildcontextdockerignore and PAX archives byte-identical with the other SDKs (shared fixtures)
Accountvolume*, secret*, reservation*, mac_model*, account*
CI.github/workflows/sdk-go-ci.yaml (new), contracts.yaml, e2e.yaml, ci-passed-rerun.yamlrace tests, golangci-lint, go mod tidy -diff, a consumer-module build
Releasesdk_publish.yaml, scripts/sdk-version.sh --go, scripts/sdk-go-publish_test.sh (runs the workflow's own shell against fakes)
AX evalsscripts/ax-evals go surface + setup/go.sh (five prompts created on Firegoat)
Docssdk-go/README.md, sdk-go/DEVELOPMENT.md, docs/RELEASING.md, docs/VERSIONING.md, changelog fragment

Size, without the generated models: about 53k lines of Go (source, unit tests and live tests) in files of at most 250 lines of code each.

Testing

  • go build ./... && go vet ./... && go vet -tags e2e ./...: pass.
  • go test -race -shuffle=on -count=2 ./...: pass. Coverage is 93.6% for daytona, 94.3% for internal/events, 83.4% for internal/buildcontext and 81.8% for internal/dockerignore. goleak checks every test binary. Shared fixtures with the other SDKs: dockerignore cases, the BuildKit corpus (329 cases), byte-identical PAX archives. A route-drift test checks every route the SDK calls against contract/. Tests that read files outside sdk-go/ skip when those files are absent (the published module zip has only sdk-go/); the repository's CI sets DAYTONA_SDK_GO_REQUIRE_FIXTURES=1, so there a missing file fails instead.
  • golangci-lint run (strict v2 config in sdk-go/.golangci.yml, e2e files included): 0 issues.
  • 57 runnable examples (go doc / pkg.go.dev).
  • Reviews: fresh independent reviewers in rounds of three (one per slice: core and lifecycle, toolbox, images/account/release). The last two full rounds and a final round over the remaining changes approved with no must-fix. cubic: every thread was fixed or answered with a parity reason (the TypeScript SDK is the reference), and its last review left no new threads. Conventions settled along the way are in sdk-go/DEVELOPMENT.md.
  • Live e2e against Daytona Cloud (DAYTONA_API_KEY=… ./e2e/run.sh go): PASS for core, lifecycle, filesystem, processes/PTY/sessions/interpreter (including output-writer failures), git, ports and public preview, docker, images (build, logs, context upload from a path and from a reader, CreateFromBuild), account and events. Skipped with a stated reason, because the test key or organization lacks them: persistent sandboxes (stop/start, pause/resume, fork), read:snapshots, read:spending (budget), the desktop addon (not in the default image), safe branch deletion (the deployed daemon still deletes an unmerged branch without force), and pulling a bucket volume.
  • scripts/sdk-version_test.sh, scripts/sdk-go-publish_test.sh, scripts/release-channel_test.sh, scripts/patch_coverage_test.sh, scripts/e2e-run_test.sh, scripts/ax-evals/setup/go_test.sh, node --test scripts/ax-evals/ax-evals.test.js: pass (the shell tests run in the Tooling tests workflow). actionlint is clean.
  • AX evals on Firegoat (Go surface, five tasks, run after every review round): all 45 runs over nine rounds succeeded. Results and the changes they drove are in the AX comment below.