CubeSandbox icon indicating copy to clipboard operation
CubeSandbox copied to clipboard

Add Gin API sandbox example

Open hyy321 opened this issue 5 months ago • 2 comments

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

hyy321 avatar Jun 30 '26 12:06 hyy321

Updated the PR based on the review comments.

Main changes:

  • Run the image as the existing non-root user from the CubeSandbox base image.
  • Clarify that port 49999 is 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 -fsSL with retry and timeout options, and remove the unused wget dependency.
  • Make the extra file-write verification opt-in via VERIFY_FILE_WRITES=1 to 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 .env relative 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 /health template probe returned 200 OK.
  • The full SDK example completed successfully, including file writes, go mod tidy, go build, starting the Gin server, and all endpoint checks.

hyy321 avatar Jul 01 '26 04:07 hyy321

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.

hyy321 avatar Jul 01 '26 09:07 hyy321