Tencent/WeKnora · error

invalid sandbox type

Error message

invalid sandbox type

What it means

ValidateConfig checks a SandboxConfig before a Manager is built. It throws 'invalid sandbox type' when config.Type is not one of the four accepted SandboxType constants: Docker, Cube, E2B, or Disabled. This guards against typos, zero-value configs, or type values from older/newer library versions reaching NewManager or NewSessionBoundManager.

Source

Thrown at internal/sandbox/sandbox.go:374

		DockerImage:     DefaultDockerImage,
		MaxMemory:       DefaultMemoryLimit,
		MaxCPU:          DefaultCPULimit,
		CubeSandboxTTL:  DefaultCubeSandboxTTL,
		CubeHTTPTimeout: DefaultCubeHTTPTimeout,
	}
}

// ValidateConfig validates sandbox configuration
func ValidateConfig(config *Config) error {
	if config == nil {
		return errors.New("config is nil")
	}

	switch config.Type {
	case SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, SandboxTypeDisabled:
		// Valid types
	default:
		return errors.New("invalid sandbox type")
	}

	if config.DefaultTimeout < 0 {
		return errors.New("timeout cannot be negative")
	}

	if config.MaxMemory < 0 {
		return errors.New("memory limit cannot be negative")
	}

	if config.MaxCPU < 0 {
		return errors.New("CPU limit cannot be negative")
	}

	return nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Set config.Type to one of the supported constants: SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, or SandboxTypeDisabled.
  2. If Type comes from user config, map/normalize the input string to a SandboxType constant before calling NewManager.
  3. Call ValidateConfig yourself before constructing a Manager and surface a clear message naming the invalid type.

Example fix

// before
cfg := sandbox.Config{DefaultTimeout: 30 * time.Second}
mgr, err := sandbox.NewManager(cfg) // "invalid sandbox type"
// after
cfg := sandbox.Config{Type: sandbox.SandboxTypeDocker, DefaultTimeout: 30 * time.Second}
mgr, err := sandbox.NewManager(cfg)
Defensive patterns

Strategy: validation

Validate before calling

func validSandboxType(t sandbox.SandboxType) bool {
    switch t {
    case sandbox.SandboxTypeDocker, sandbox.SandboxTypeCube, sandbox.SandboxTypeE2B, sandbox.SandboxTypeDisabled:
        return true
    }
    return false
}
if !validSandboxType(cfg.Type) { return fmt.Errorf("unsupported sandbox type %q", cfg.Type) }
if err := sandbox.ValidateConfig(cfg); err != nil { return fmt.Errorf("sandbox config: %w", err) }

Type guard

func isKnownSandboxType(t sandbox.SandboxType) bool {
    switch t {
    case sandbox.SandboxTypeDocker, sandbox.SandboxTypeCube, sandbox.SandboxTypeE2B, sandbox.SandboxTypeDisabled:
        return true
    default:
        return false
    }
}

Try / catch

if _, err := sandbox.NewManager(cfg); err != nil {
    if err.Error() == "invalid sandbox type" {
        return fmt.Errorf("unsupported sandbox type %q; use docker|cube|e2b|disabled", cfg.Type)
    }
    return err
}

Prevention

When it happens

Trigger: Calling NewManager or NewSessionBoundManager with a SandboxConfig whose Type field is unset (zero value) or set to anything other than SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, or SandboxTypeDisabled.

Common situations: Constructing Config{} without setting Type; hand-writing a type string from docs or an older release that no longer matches current SandboxType constants; deserializing JSON/YAML config with an unrecognized 'type' value.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/ad7921578e0f6e76. Report an issue: GitHub.