CubeSandbox
CubeSandbox copied to clipboard
Add Gin API sandbox example
This PR adds a Gin API sandbox example.
It includes:
- Dockerfile for building a Go/Gin runtime template
- E2B-compatible SDK example for creating a sandbox from the template
- Multi-file Gin project written into /workspace/app
- Build and start flow with go mod tidy and go build
- HTTP endpoint tests for /health, /users/:id, and POST /users
- README with use cases, resource recommendations, known limitations, and deployment notes
Verified locally with CubeSandbox deployment.
Related to #682
Updated the PR based on the review comments.
Main changes:
- Run the image as the existing non-root
userfrom the CubeSandbox base image. - Clarify that port
49999is reserved for the CubeSandbox template health probe. - Pin apt package versions for a more reproducible image build.
- Add SHA256 verification for the downloaded Go tarball before extraction.
- Switch the Go toolchain download to
curl -fsSLwith retry and timeout options, and remove the unusedwgetdependency. - Make the extra file-write verification opt-in via
VERIFY_FILE_WRITES=1to avoid unnecessary sandbox round-trips. - Parse JSON responses in endpoint checks and compare specific fields instead of relying on substring matching.
- Refactor the Gin server startup logic into a Python helper for better readability.
- Load
.envrelative to the script directory. - Add a
main()guard and avoid import-time side effects.
I also re-tested the updated example successfully:
- Docker image build passed.
- The
49999 /healthtemplate probe returned200 OK. - The full SDK example completed successfully, including file writes,
go mod tidy,go build, starting the Gin server, and all endpoint checks.
Got it, thanks for the suggestion. I’ll take a look at CubeMaster/pkg/service/httpservice/cube/cube.go and try to refactor the existing net/http style handlers into Gin routes. I’ll open a draft PR after I understand the current routing logic.