{"record":{"id":"8450fee37409a7ac","repo":"Tencent/WeKnora","slug":"build-e2b-client-w","errorCode":null,"errorMessage":"build e2b client: %w","messagePattern":"build e2b client: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/e2b_remote_client.go","lineNumber":97,"sourceCode":"\ttimeout := cfg.E2BHTTPTimeout\n\tif timeout <= 0 {\n\t\ttimeout = DefaultE2BHTTPTimeout\n\t}\n\t// Every E2B client speaks to envd through the compatibility shim, whether\n\t// or not a gateway is configured: the two details it rewrites belong to the\n\t// envd protocol itself, not to any one deployment. See envd_compat_transport.go.\n\thttpClient := &http.Client{\n\t\tTimeout:   timeout,\n\t\tTransport: NewEnvdCompatTransport(transport, DefaultSandboxExecUser),\n\t}\n\tclient, err := e2b.NewClient(e2b.ClientConfig{\n\t\tAPIKey:        cfg.E2BAPIKey,\n\t\tAPIBaseURL:    strings.TrimSpace(cfg.E2BAPIURL),\n\t\tSandboxDomain: strings.TrimSpace(cfg.E2BSandboxDomain),\n\t\tHTTPClient:    httpClient,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"build e2b client: %w\", err)\n\t}\n\n\tttl := cfg.E2BSandboxTTL\n\tif ttl <= 0 {\n\t\tttl = DefaultE2BSandboxTTL\n\t}\n\treturn &E2BRemoteClient{\n\t\tclient:     client,\n\t\ttemplateID: strings.TrimSpace(cfg.E2BTemplate),\n\t\ttimeout:    ttl,\n\t}, nil\n}\n\n// e2bRemoteHandle is the RemoteSandboxHandle E2B returns. It carries the\n// *e2b.Sandbox so subsequent envd calls can reuse its access token.\ntype e2bRemoteHandle struct {\n\tsandbox  *e2b.Sandbox\n\tmetadata map[string]string","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/e2b_remote_client.go#L79-L115","documentation":"newE2BRemoteClient constructs the E2B SDK client with API key, base URL, sandbox domain, and a custom HTTP transport. If the E2B SDK's client constructor returns an error (e.g. missing/invalid API key or malformed options), it is wrapped as \"build e2b client: %w\" and client creation aborts.","triggerScenarios":"Calling NewE2BRemoteClientWithTransport or NewE2BRemoteClientWithPool when the underlying e2b.NewClient call fails — typically an empty E2BAPIKey or an invalid APIBaseURL/SandboxDomain passed in Config.","commonSituations":"E2B_API_KEY environment variable not set or injected into Config; typo'd E2BAPIURL pointing to a non-E2B endpoint; enterprise self-hosted E2B deployments with a wrong SandboxDomain; SDK version upgrade changing constructor validation rules.","solutions":["Set cfg.E2BAPIKey (or the E2B_API_KEY env var) to a valid API key before constructing the client.","Verify cfg.E2BAPIURL and cfg.E2BSandboxDomain are correct for your deployment (cloud vs self-hosted).","Inspect the wrapped cause with errors.Unwrap / %v of the returned error for the SDK's specific complaint.","Pin/upgrade the e2b SDK version to one compatible with the config fields being set."],"exampleFix":"// before\ncfg := &Config{} // E2BAPIKey empty\nclient, err := NewE2BRemoteClient(cfg)\n// after\ncfg := &Config{E2BAPIKey: os.Getenv(\"E2B_API_KEY\")}\nif cfg.E2BAPIKey == \"\" { return nil, errors.New(\"E2B_API_KEY required\") }\nclient, err := NewE2BRemoteClient(cfg)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(cfg.E2BAPIKey) == \"\" {\n    return errors.New(\"E2BAPIKey is required\")\n}","typeGuard":"func e2bConfigReady(cfg *Config) bool {\n    return cfg != nil && strings.TrimSpace(cfg.E2BAPIKey) != \"\"\n}","tryCatchPattern":"client, err := NewE2BRemoteClient(cfg)\nif err != nil {\n    var berr *BuildError\n    if errors.As(err, &berr) { /* inspect wrapped SDK cause */ }\n    return fmt.Errorf(\"e2b unavailable: %w\", err)\n}","preventionTips":["Load E2B_API_KEY from env at startup and fail fast if missing","Validate E2BAPIURL/SandboxDomain formats before constructing clients","Pin the e2b SDK version and review its constructor requirements on upgrades"],"tags":["e2b","client-construction","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}