{"record":{"id":"d9b7474de75af9f5","repo":"Tencent/WeKnora","slug":"sandbox-create-input-directory-w","errorCode":null,"errorMessage":"sandbox: create input directory: %w","messagePattern":"sandbox: create input directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/session_manager.go","lineNumber":521,"sourceCode":"func (m *SessionBoundManager) WriteSessionInputFile(\n\tctx context.Context, sessionID, filePath string, content []byte,\n) error {\n\tif err := m.requireRemoteBackend(); err != nil {\n\t\treturn err\n\t}\n\tif strings.TrimSpace(sessionID) == \"\" {\n\t\treturn errors.New(\"sandbox: session ID required for input staging\")\n\t}\n\tclean, err := cleanSessionInputPath(filePath)\n\tif err != nil {\n\t\treturn err\n\t}\n\thandle, err := m.resolveSession(ctx, sessionID)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := ignoreExistingDir(m.client.MakeDir(ctx, handle, path.Dir(clean))); err != nil {\n\t\treturn fmt.Errorf(\"sandbox: create input directory: %w\", err)\n\t}\n\tif err := m.client.WriteFile(ctx, handle, clean, content); err != nil {\n\t\treturn fmt.Errorf(\"sandbox: write session input %s: %w\", clean, err)\n\t}\n\treturn nil\n}\n\n// WriteSessionWorkspaceFile writes a model-authored file into the session's\n// remote sandbox, provisioning the sandbox on first call. Paths must sit\n// under /workspace and must not land in /workspace/input.\nfunc (m *SessionBoundManager) WriteSessionWorkspaceFile(\n\tctx context.Context, sessionID, filePath string, content []byte,\n) error {\n\tif err := m.requireRemoteBackend(); err != nil {\n\t\treturn err\n\t}\n\tif strings.TrimSpace(sessionID) == \"\" {\n\t\treturn errors.New(\"sandbox: session ID required for workspace write\")","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/session_manager.go#L503-L539","documentation":"WriteSessionInputFile resolves the session (provisioning the sandbox if needed via resolveSession) and first creates the parent directory of the cleaned target path with MakeDir, wrapped as \"sandbox: create input directory\". It indicates the parent directory for a staged attachment could not be created in the remote sandbox.","triggerScenarios":"Calling WriteSessionInputFile when MakeDir on path.Dir(clean) fails after resolveSession succeeded — e.g. permission denied, invalid parent path, sandbox terminated between provision and mkdir, or provider API error.","commonSituations":"Attachment path with unexpected characters or bad nesting, sandbox image restricting writes to the input root, provider quota exceeded, or race with sandbox cleanup.","solutions":["Check the wrapped error for permission vs. invalid-path causes.","Ensure the target path resolves under the session input root and uses provider-safe characters.","Verify the sandbox is still alive and re-resolve the session, then retry.","Check provider disk/quota limits."],"exampleFix":"// before\nerr := mgr.WriteSessionInputFile(ctx, sessionID, \"../../etc/evil.txt\", data)\n// after\nclean := path.Clean(filepath.Join(\"/inputs\", attachmentName))\nerr := mgr.WriteSessionInputFile(ctx, sessionID, clean, data)","handlingStrategy":"validation","validationCode":"// validate the attachment path before writing\nfunc validInputPath(p string) bool {\n    clean := path.Clean(p)\n    return path.IsAbs(clean) && !strings.Contains(clean, \"..\") &&\n        strings.HasPrefix(clean, \"/inputs/\")\n}","typeGuard":null,"tryCatchPattern":"if err := mgr.WriteSessionInputFile(ctx, sessionID, p, data); err != nil {\n    if strings.Contains(err.Error(), \"create input directory\") {\n        // sandbox may have expired mid-call: re-resolve and retry once\n        return mgr.WriteSessionInputFile(ctx, sessionID, p, data)\n    }\n    return err\n}","preventionTips":["Sanitize attachment filenames (strip odd characters, force clean absolute paths under the input root).","Keep attachments within expected size limits to avoid slow uploads expiring the sandbox.","Check sandbox liveness before long write sequences.","Log the wrapped error chain to distinguish mkdir vs. write failures."],"tags":["go","sandbox","filesystem","path"],"backgroundTag":"remote-mkdir-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}