feat(sdk-go): add the Go SDK, go.daytona.com/sdk/v2
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:
| Concern | Python / TypeScript | Go |
|---|---|---|
| Durations | wait_seconds / waitSeconds numbers | time.Duration everywhere; daytona.NoWait, daytona.WaitForever, daytona.NoTimeout sentinels |
| Optional arguments | keyword args / option bags | *XxxOptions last, nil = all defaults |
| Cancellation | timeouts | ctx context.Context first on every call; cancellation also stops waits |
| Errors | class hierarchy | *daytona.Error + errors.Is(err, daytona.ErrNotFound) (category) and errors.Is(err, daytona.ErrSandboxNotRunning) (code) |
| Lists | pages / async iterators | List → *Page[T], ListAll → iter.Seq2[T, error] |
| Streams and files | callbacks, Blobs, paths | io.Reader / io.Writer, local paths, iter.Seq2 for event streams |
| v0 API | Daytona().v0 namespace bundled into 2.x | none: Go builds two major versions side by side, so v0 code keeps importing github.com/daytona/clients/sdk-go next to this module |
| Tracing | built-in OTel option | wrap 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
/v2path suffix is Go's major-version rule.go get -u,@latestand Dependabot never move a module across majors. - The 0.x module also reads
sdk-go/*tags, but Go ignoresv2+for a path without a/v2suffix. The publish workflow therefore refuses any Go version whose major is not the suffix insdk-go/go.mod, so asdk-go/v0.*orsdk-go/v1.*tag can never come frommain. - The go-import tag uses the subdirectory field from Go 1.25, which keeps
sdk-goout of the import path. I checked this end to end with Go 1.26.10 against a local repo holding bothsdk-go/v0.xandsdk-go/v2.xtags:go get,go get <pkg>@v2.1.0,go mod tidyandgo get -uall 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'sclient_rules.early_probesays 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, thenassignedon the next read). The SDKs report what each read says; the live tests re-read untilstarted. GET /files/watchcan end with anerrorenvelope (contract: macOS access denials). No SDK maps it yet (TypeScriptFileSystem.ts:647-655skips 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
| Area | Files | |
|---|---|---|
| Module scaffold, wire models | sdk-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 |
| Core | client*, 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) | |
| Lifecycle | sandbox_create*, create_*, sandbox_lifecycle*, sandbox_wait*, policies, labels, env, network policy, sandbox secrets, access tokens, metrics, macOS | waits 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 |
| Events | events*, internal/events | sandbox-state WebSocket hub per contract/sandbox-events-protocol.json |
| Toolbox | fs*, transfer*, watch*, process*, exec*, pty*, session*, interpreter*, git*, ports*, docker*, sandbox_volumes*, computer_use* | |
| Images | image*, images*, builder*, build_logs*, context_upload*, snapshot*, internal/dockerignore, internal/buildcontext | dockerignore and PAX archives byte-identical with the other SDKs (shared fixtures) |
| Account | volume*, secret*, reservation*, mac_model*, account* | |
| CI | .github/workflows/sdk-go-ci.yaml (new), contracts.yaml, e2e.yaml, ci-passed-rerun.yaml | race tests, golangci-lint, go mod tidy -diff, a consumer-module build |
| Release | sdk_publish.yaml, scripts/sdk-version.sh --go, scripts/sdk-go-publish_test.sh (runs the workflow's own shell against fakes) | |
| AX evals | scripts/ax-evals go surface + setup/go.sh (five prompts created on Firegoat) | |
| Docs | sdk-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% fordaytona, 94.3% forinternal/events, 83.4% forinternal/buildcontextand 81.8% forinternal/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 againstcontract/. Tests that read files outsidesdk-go/skip when those files are absent (the published module zip has onlysdk-go/); the repository's CI setsDAYTONA_SDK_GO_REQUIRE_FIXTURES=1, so there a missing file fails instead.golangci-lint run(strict v2 config insdk-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.