diff --git a/internal/infrastructure/openshell/runtime.go b/internal/infrastructure/openshell/runtime.go index 4ba6ca3e6..108186170 100644 --- a/internal/infrastructure/openshell/runtime.go +++ b/internal/infrastructure/openshell/runtime.go @@ -5,6 +5,8 @@ package openshell import ( "context" + "crypto/rand" + "encoding/hex" "errors" "fmt" "log/slog" @@ -151,7 +153,10 @@ func (s *Sandbox) ExitDetail() string { // Acquire creates a sandbox running the agent l describes, and waits until it // is ready. func (r *Runtime) Acquire(ctx context.Context, l Launch) (*Sandbox, error) { - name := fmt.Sprintf("%s-agent-%d", r.instance, time.Now().UnixNano()) + name, err := sandboxName() + if err != nil { + return nil, err + } spec, err := r.spec(l) if err != nil { return nil, err @@ -170,6 +175,16 @@ func (r *Runtime) Acquire(ctx context.Context, l Launch) (*Sandbox, error) { return s, nil } +// sandboxName is a short random name: the gateway rejects names much longer +// than 19 characters, and the instance is carried by the sandbox's label. +func sandboxName() (string, error) { + var b [6]byte + if _, err := rand.Read(b[:]); err != nil { + return "", fmt.Errorf("name sandbox: %w", err) + } + return "archie-" + hex.EncodeToString(b[:]), nil +} + // Release stops watching s and removes its sandbox. func (r *Runtime) Release(ctx context.Context, s *Sandbox) { if s == nil {