{"record":{"id":"551da12c909a5395","repo":"Tencent/WeKnora","slug":"sandbox-s-template-id-is-required-but-not-config","errorCode":null,"errorMessage":"sandbox: %s template ID is required but not configured","messagePattern":"sandbox: (.+?) template ID is required but not configured","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/session_manager.go","lineNumber":168,"sourceCode":"\tcase SandboxTypeCube:\n\t\tapplyCubeRuntimeDefaults(cfg)\n\tcase SandboxTypeE2B:\n\t\tapplyE2BRuntimeDefaults(cfg)\n\tcase SandboxTypeDocker:\n\t\tapplyDockerRuntimeDefaults(cfg)\n\t}\n\n\t// Build the provider-specific neutral create request using the\n\t// provider's own template and TTL fields.\n\tcreateRequest, err := buildSessionCreateRequest(provider, cfg)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"session bound manager: %w\", err)\n\t}\n\t// An empty template for the selected provider means the deployment is\n\t// misconfigured. Fail early so operators get a clear message instead of\n\t// a remote API error at the first sandbox allocation.\n\tif strings.TrimSpace(createRequest.TemplateID) == \"\" {\n\t\treturn nil, fmt.Errorf(\n\t\t\t\"sandbox: %s template ID is required but not configured\",\n\t\t\tprovider,\n\t\t)\n\t}\n\n\tclient := wrapLangfuseRemoteClient(deps.Client)\n\n\tlifecycle, err := newRemoteSessionLifecycle(\n\t\tclient,\n\t\tdeps.Store,\n\t\tdeps.Checker,\n\t\tcreateRequest,\n\t\tsessionLifecycleCleanupTimeout,\n\t\tdeps.ConfigID,\n\t)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"session bound manager: %w\", err)\n\t}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/session_manager.go#L150-L186","documentation":"The manager deliberately fails fast at construction when the selected provider's create request has an empty TemplateID. A blank template means the deployment is misconfigured; without this check the user would get an opaque remote API error only at the first sandbox allocation.","triggerScenarios":"NewSessionBoundManager is called with a Config where the provider's template ID field is empty or whitespace — e.g. E2B/Cube template env var unset, a named config omitting the template, or defaults intentionally not supplying endpoints/templates.","commonSituations":"Missing SANDBOX_TEMPLATE_ID-style env vars in a new deployment; renaming config keys during migration so the template value is no longer read; per-tenant configs created without the template field.","solutions":["Set the template ID for the resolved provider in your config/environment","If using named configs, add the required template field explicitly (defaults are deliberately not filled in)","Verify the env var/config key is actually being loaded into the Config struct (log cfg before construction)","Confirm deps.Client.Provider() matches the provider whose template you configured"],"exampleFix":"// before\ncfg := sandbox.DefaultConfig()\nmgr, _ := sandbox.NewSessionBoundManager(sandbox.SessionBoundManagerConfig{Config: cfg, ...})\n// after\ncfg := sandbox.DefaultConfig()\ncfg.TemplateID = os.Getenv(\"SANDBOX_TEMPLATE_ID\") // must be non-empty\nmgr, _ := sandbox.NewSessionBoundManager(sandbox.SessionBoundManagerConfig{Config: cfg, ...})","handlingStrategy":"validation","validationCode":"cfg := deps.Config\nif cfg == nil { cfg = sandbox.DefaultConfig() }\nif strings.TrimSpace(cfg.TemplateID) == \"\" {\n    return nil, errors.New(\"template ID must be set before constructing manager\")\n}","typeGuard":null,"tryCatchPattern":"mgr, err := sandbox.NewSessionBoundManager(deps)\nif err != nil && strings.Contains(err.Error(), \"template ID is required but not configured\") {\n    return nil, fmt.Errorf(\"set the provider template ID in config/env: %w\", err)\n}","preventionTips":["Fail fast at deployment time if the template env var is empty","Include template ID in startup config logging (value masked if sensitive)","For named configs, always fill required fields explicitly — defaults are intentionally not applied"],"tags":["go","configuration","template","missing-env-var"],"backgroundTag":"missing-env-var","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}