{"record":{"id":"ad7921578e0f6e76","repo":"Tencent/WeKnora","slug":"invalid-sandbox-type","errorCode":null,"errorMessage":"invalid sandbox type","messagePattern":"invalid sandbox type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/sandbox.go","lineNumber":374,"sourceCode":"\t\tDockerImage:     DefaultDockerImage,\n\t\tMaxMemory:       DefaultMemoryLimit,\n\t\tMaxCPU:          DefaultCPULimit,\n\t\tCubeSandboxTTL:  DefaultCubeSandboxTTL,\n\t\tCubeHTTPTimeout: DefaultCubeHTTPTimeout,\n\t}\n}\n\n// ValidateConfig validates sandbox configuration\nfunc ValidateConfig(config *Config) error {\n\tif config == nil {\n\t\treturn errors.New(\"config is nil\")\n\t}\n\n\tswitch config.Type {\n\tcase SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, SandboxTypeDisabled:\n\t\t// Valid types\n\tdefault:\n\t\treturn errors.New(\"invalid sandbox type\")\n\t}\n\n\tif config.DefaultTimeout < 0 {\n\t\treturn errors.New(\"timeout cannot be negative\")\n\t}\n\n\tif config.MaxMemory < 0 {\n\t\treturn errors.New(\"memory limit cannot be negative\")\n\t}\n\n\tif config.MaxCPU < 0 {\n\t\treturn errors.New(\"CPU limit cannot be negative\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":356,"sourceCodeEnd":391,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/sandbox.go#L356-L391","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set config.Type to one of the supported constants: SandboxTypeDocker, SandboxTypeCube, SandboxTypeE2B, or SandboxTypeDisabled.","If Type comes from user config, map/normalize the input string to a SandboxType constant before calling NewManager.","Call ValidateConfig yourself before constructing a Manager and surface a clear message naming the invalid type."],"exampleFix":"// before\ncfg := sandbox.Config{DefaultTimeout: 30 * time.Second}\nmgr, err := sandbox.NewManager(cfg) // \"invalid sandbox type\"\n// after\ncfg := sandbox.Config{Type: sandbox.SandboxTypeDocker, DefaultTimeout: 30 * time.Second}\nmgr, err := sandbox.NewManager(cfg)","handlingStrategy":"validation","validationCode":"func validSandboxType(t sandbox.SandboxType) bool {\n    switch t {\n    case sandbox.SandboxTypeDocker, sandbox.SandboxTypeCube, sandbox.SandboxTypeE2B, sandbox.SandboxTypeDisabled:\n        return true\n    }\n    return false\n}\nif !validSandboxType(cfg.Type) { return fmt.Errorf(\"unsupported sandbox type %q\", cfg.Type) }\nif err := sandbox.ValidateConfig(cfg); err != nil { return fmt.Errorf(\"sandbox config: %w\", err) }","typeGuard":"func isKnownSandboxType(t sandbox.SandboxType) bool {\n    switch t {\n    case sandbox.SandboxTypeDocker, sandbox.SandboxTypeCube, sandbox.SandboxTypeE2B, sandbox.SandboxTypeDisabled:\n        return true\n    default:\n        return false\n    }\n}","tryCatchPattern":"if _, err := sandbox.NewManager(cfg); err != nil {\n    if err.Error() == \"invalid sandbox type\" {\n        return fmt.Errorf(\"unsupported sandbox type %q; use docker|cube|e2b|disabled\", cfg.Type)\n    }\n    return err\n}","preventionTips":["Always set Type explicitly via a SandboxType constant, never a raw string.","Normalize user-supplied type strings through a whitelist map before constructing Config.","Call ValidateConfig in tests for every config-loading path."],"tags":["go","sandbox","configuration","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}