feat(sdk): Go SDK with oapi-codegen for Lifecycle, Execd, and Egress APIs#597
feat(sdk): Go SDK with oapi-codegen for Lifecycle, Execd, and Egress APIs#597AlexandrePh wants to merge 16 commits intoalibaba:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Go SDK (stdlib-only) for OpenSandbox’s Lifecycle, Execd, and Egress APIs, including an SSE streaming implementation and an httptest-based test suite.
Changes:
- Introduce typed Go clients for Lifecycle, Execd, and Egress APIs plus shared HTTP/error helpers.
- Implement SSE streaming support used by Execd streaming endpoints.
- Add Go module scaffolding, README, Makefile, and a test suite covering core behaviors.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| sdks/sandbox/go/opensandbox/types.go | Shared SDK types and error types used across clients |
| sdks/sandbox/go/opensandbox/http.go | Base HTTP client, JSON helpers, and API error handling |
| sdks/sandbox/go/opensandbox/streaming.go | SSE parsing + streaming request helper |
| sdks/sandbox/go/opensandbox/lifecycle.go | Lifecycle API client methods (create/get/list/etc.) |
| sdks/sandbox/go/opensandbox/egress.go | Egress policy client methods |
| sdks/sandbox/go/opensandbox/execd.go | Execd client methods (SSE execution, files, dirs, metrics) |
| sdks/sandbox/go/opensandbox/opensandbox_test.go | httptest-based unit tests for clients + SSE behavior |
| sdks/sandbox/go/go.mod | New Go module definition for the SDK |
| sdks/sandbox/go/README.md | Installation, examples, and API reference documentation |
| sdks/sandbox/go/Makefile | Build/vet/test/lint targets for the SDK module |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6ddbba4 to
eee4958
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 70f495e992
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…APIs - oapi-codegen generates typed clients from all 3 OpenAPI specs - Hand-written ergonomic wrapper for SSE/NDJSON streaming, multipart uploads, file downloads - 18 unit tests + integration test (local) + staging test (remote K8s) - `make generate` target + `go generate ./...` for spec-driven regeneration - All review feedback addressed (streaming timeout, scanner buffer, type safety, FileMode encoding) - No hardcoded credentials — staging tests require STAGING_URL and STAGING_API_KEY env vars Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
70f495e to
254cd8f
Compare
|
Great Job! It's great to see the SDK for a new language. 🎉🎉 Perhaps you could refer to the e2e tests under the |
All review feedback addressedThe branch was squashed into a single clean commit. All 10 Copilot and 2 Codex review comments from the previous revision are addressed:
Additionally:
|
|
Thanks for the feedback! 🙏 We're actively working on this — the plan is:
Will push an update soon. |
High-level API matching Python/JS/C#/Java SDKs: - ConnectionConfig: shared config with env var fallbacks (OPEN_SANDBOX_DOMAIN, OPEN_SANDBOX_API_KEY) - Sandbox: high-level object with CreateSandbox(), ConnectSandbox(), auto-endpoint resolution, WaitUntilReady() - SandboxManager: list, filter, kill, pause, resume, renew operations - Execution model: structured stdout/stderr, exit codes, event handlers - Error types: SandboxReadyTimeoutError, SandboxUnhealthyError, InvalidArgumentError - Constants: DefaultExecdPort, DefaultTimeoutSeconds, DefaultResourceLimits, etc. E2E tests in tests/go/ (12 tests, all passing against live staging): - Sandbox lifecycle: create, info, metrics, renew, endpoint, kill - Command execution: simple run, handlers, exit codes, multi-line - Filesystem: file info, write + read via commands - Manager: list, filter by state, get + kill Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Done! Pushed the high-level API and e2e tests. What's newHigh-level API (matching Python/JS/C#/Java SDKs): sb, err := opensandbox.CreateSandbox(ctx, config, opensandbox.SandboxCreateOptions{
Image: "python:3.11-slim",
})
defer sb.Kill(ctx)
exec, err := sb.RunCommand(ctx, "echo hello", nil)
fmt.Println(exec.Text()) // "hello"
fmt.Println(*exec.ExitCode) // 0
E2E tests in |
…r, context-aware polling - Extract clientOpts() helper to deduplicate option building in config.go - Use strings.Builder in Execution.Text() instead of O(n²) string concat - waitForRunning now respects context cancellation instead of hardcoded 120 iterations - Remove SandboxFilter duplication — use ListOptions throughout - Use SandboxState constants instead of string literals in tests - Extract createTestSandbox() helper to reduce e2e test boilerplate Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Once you're done with the development, please mark the PR as ready to review (convert it from draft) : > |
…directories New e2e tests (19 total, up from 12): - Filesystem: write/read/delete cycle, move files, create/delete directories, search files, download file - Sandbox: connect to existing sandbox, bash sessions with state persistence - Fix CreateDirectory to send mode as int per server spec New Sandbox methods exposed: - DeleteFiles, MoveFiles, SearchFiles, SetPermissions, ReplaceInFiles - UploadFile, DownloadFile, CreateDirectory, DeleteDirectory - ExecuteCode, CreateContext, ListContexts, DeleteContext - CreateSession, RunInSession, DeleteSession Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- CodeInterpreter type wrapping Sandbox with code execution capabilities - CreateCodeInterpreter() factory with opensandbox/code-interpreter:latest image - Execute() for quick language-based execution - ExecuteInContext() for persistent state across executions E2E tests (6 new, 25 total): - Create and ping code-interpreter sandbox - Python code execution - Context persistence (variables survive across calls) - Context management (create, list, delete) - Context isolation (variables don't leak between contexts) - Execution with handlers (streaming stdout) All 25 e2e tests pass against live K8s staging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… policy, x-request-id New e2e tests (35 total, up from 25): - Command: env injection, background status/logs, interrupt - Sandbox: manual cleanup, network policy create, egress get/patch, pause/resume - Volumes: host mount (rw + readonly), PVC mount - Error: x-request-id passthrough on API errors - APIError now carries RequestID from X-Request-Id response header Fix: CreateDirectory sends mode as octal-digits integer per server spec. Tests that require egress sidecar, PVC, or pause support gracefully skip. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Three scenario tests using live Bifrost (Azure OpenAI) + OpenSandbox: 1. SimpleAgentLoop: task → LLM generates Python → execute in sandbox → verify result (Fibonacci sequence via gpt-4o-mini generated code) 2. CodeInterpreterAgent: multi-turn agent with persistent Python context (Create dataset → LLM analyzes with stdlib → variables persist across turns) 3. SandboxToolUse: LLM as shell command planner (LLM decides what command → sandbox executes → LLM interprets output) All 3 tests pass against live staging (Bifrost → Azure OpenAI gpt-4o-mini). Also: configured Bifrost with Azure OpenAI provider (gpt-4o, gpt-4o-mini, o4-mini) via azure-gpt-sharpi endpoint in Brazil South. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two runnable examples demonstrating real-world usage: 1. examples/agent_loop/ — Simple agent: task → LLM → Python code → sandbox → result 2. examples/code_interpreter_agent/ — Multi-turn agent with persistent Python state Both use env vars for all config (OPEN_SANDBOX_DOMAIN, LLM_ENDPOINT, etc.) No hardcoded credentials. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ccuracy 1. OctalMode: panic on invalid FileMode instead of silently returning 0 2. CodeInterpreter timeout: use named constant DefaultCodeInterpreterTimeoutSeconds 3. GetBaseURL doc: fix misleading comment that claimed /v1 suffix 4. resolveExecd/resolveEgress: use sync.Once for goroutine-safe initialization 5. execution.go: rename `init` variable to `initEvent` to avoid shadowing builtin 6. execd.go: remove duplicate doc comment on CreateDirectory 7. types.go: fix SandboxInfo doc comment that still said "Sandbox" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
sync.Once captures the first caller's context permanently — if it fails, subsequent retries are impossible. Replaced with mutex-guarded check-then-init which respects each caller's context and retries on failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… passes - TestConcurrent_CreateFiveSandboxes: creates 5 sandboxes in parallel, verifies each is healthy and responds independently (requires 3/5 minimum for resource-constrained staging clusters) - TestVolume_PVCMount now passes after provisioning opensandbox-e2e-pvc-test PVC via local-path provisioner on staging Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 43 out of 45 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… assertions
8 fixes from Copilot's second review pass:
1. execution.go: Handle nested error/results JSON per execd spec
({"type":"error","error":{...}} and {"type":"result","results":{...}})
with backward compat for flat fields from older servers
2. config.go: Wire RequestTimeout and Headers into clientOpts()
3. http.go: Add WithHeaders option for custom headers on requests
4. streaming.go: Populate StreamEvent.Event from NDJSON type field
5. sandbox.go: Fix doc comment — nil timeout uses client default, not server
6. README.md: Fix streaming example to parse NDJSON type field
7. volume_e2e_test.go: Assert read-only mount actually rejects writes
8. scenario_agent_e2e_test.go: Check error from write command before exec
9. config.go: Append /v1 to lifecycle client base URL
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The execd spec defines error events with a nested `error` object
(`{ename, evalue, traceback}`) and result events with a MIME-keyed
`results` map (`{"text/plain": "4"}`). The SDK was parsing these as
flat top-level fields. Now supports both formats for backward compat.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Update streaming example to use event.Event (now populated from NDJSON type) - Fix RenewExpiration signature: takes expiresAt, not duration - Fix GetEndpoint signature: add useServerProxy parameter - Fix DeleteDirectory signature: remove recursive parameter - Update StreamEvent docs to reflect NDJSON type extraction Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@ninan-nn ready for review :) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d83a932ae6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…ming - resolveExecd/resolveEgress now forward all endpoint headers (e.g. routing headers like OPEN-SANDBOX-INGRESS) to the client, not just the auth token - doStreamRequest now applies c.headers, matching doRequest behavior Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
done! executed tests against live remote server |
Summary
Go SDK with oapi-codegen for all 3 OpenSandbox APIs, plus a high-level
Sandboxobject matching the Python/JS/C#/Java SDKs.opensandbox/api/) from OpenAPI specs via oapi-codegenCreateSandbox(),ConnectSandbox(),SandboxManager,CodeInterpreterConnectionConfigwith env var fallbacks,WaitUntilReady()with custom health checksExecutionmodel with stdout/stderr, exit codes, and event handlersStreamEvent.Eventpopulated from NDJSONtypefield), multipart upload, file downloadexamples/agent_loop/andexamples/code_interpreter_agent/Closes #596
Testing
Breaking Changes
Checklist
Architecture