(.venv) root@lima-k8s:~/code# cat /root/svc.py
import asyncio
from k8s_agent_sandbox import AsyncSandboxClient
from k8s_agent_sandbox.models import SandboxDirectConnectionConfig
async def main():
config = SandboxDirectConnectionConfig(
api_url="http://sandbox-router-svc.default.svc.cluster.local:8080"
)
async with AsyncSandboxClient(connection_config=config) as client:
sandbox = await client.create_sandbox(
template="python-sandbox-template",
namespace="default",
)
result = await sandbox.commands.run("echo 'Hello from async!'")
print(result.stdout)
asyncio.run(main())
(.venv) root@lima-k8s:~/code# python3 /root/svc.py
Hello from async!
(.venv) root@lima-k8s:~/code# cat main.go
package main
import (
"context"
"fmt"
"log"
"sigs.k8s.io/agent-sandbox/clients/go/sandbox"
)
func main() {
ctx := context.Background()
templateName := "python-sandbox-template"
// Create client with shared configuration.
client, err := sandbox.NewClient(ctx, sandbox.Options{
APIURL: "http://sandbox-router-svc.default.svc.cluster.local:8080",
TemplateName: templateName,
Namespace: "default",
})
if err != nil {
log.Fatal(err)
}
stop := client.EnableAutoCleanup()
defer stop()
defer client.DeleteAll(ctx)
// Create a sandbox.
sb, err := client.CreateSandbox(ctx, templateName, "default")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Sandbox ready: claim=%s sandbox=%s pod=%s\n",
sb.ClaimName(), sb.SandboxName(), sb.PodName())
// Run a command.
result, err := sb.Run(ctx, "echo 'Hello from Go!'")
if err != nil {
log.Fatal(err)
}
fmt.Printf("stdout: %s\n", result.Stdout)
fmt.Printf("exit_code: %d\n", result.ExitCode)
// Write and read a file.
if err := sb.Write(ctx, "hello.txt", []byte("Hello, world!")); err != nil {
log.Fatal(err)
}
data, err := sb.Read(ctx, "hello.txt")
if err != nil {
log.Fatal(err)
}
fmt.Printf("file content: %s\n", string(data))
}
(.venv) root@lima-k8s:~/code# go run main.go
"ts"="2026-06-02 11:43:07.776181" "level"=0 "msg"="claim created" "claim"="sandbox-claim-s9v94" "namespace"="default"
"ts"="2026-06-02 11:43:07.806052" "level"=0 "msg"="sandbox name resolved" "claim"="sandbox-claim-s9v94" "sandbox"="sandbox-claim-s9v94"
"ts"="2026-06-02 11:43:08.787491" "level"=0 "msg"="API URL discovered" "url"="http://sandbox-router-svc.default.svc.cluster.local:8080" "mode"="direct"
Sandbox ready: claim=sandbox-claim-s9v94 sandbox=sandbox-claim-s9v94 pod=sandbox-claim-s9v94
"ts"="2026-06-02 11:43:08.799804" "msg"="retries exhausted" "error"="POST execute returned status 502: {\"detail\":\"Could not connect to the backend sandbox: sandbox-claim-s9v94\"}" "method"="POST" "url"="http://sandbox-router-svc.default.svc.cluster.local:8080/execute" "attempts"=1 "lastStatus"=502 "reqID"="84f90af32584e400" "sandbox"="sandbox-claim-s9v94" "namespace"="default"
2026/06/02 11:43:08 sandbox[default/sandbox-claim-s9v94]: run failed: retries exhausted: POST failed after 1 attempts (url=http://sandbox-router-svc.default.svc.cluster.local:8080/execute reqID=84f90af32584e400): POST execute returned status 502: {"detail":"Could not connect to the backend sandbox: sandbox-claim-s9v94"}
What happened?
golang api run command failed
How can we reproduce it (as minimally and precisely as possible)?
golang
go run main.go
Version
v0.4.6
Anything else we need to know?
No response