Tencent/WeKnora · error

sandbox: create input directory: %w

Error message

sandbox: create input directory: %w

What it means

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.

Source

Thrown at internal/sandbox/session_manager.go:521

func (m *SessionBoundManager) WriteSessionInputFile(
	ctx context.Context, sessionID, filePath string, content []byte,
) error {
	if err := m.requireRemoteBackend(); err != nil {
		return err
	}
	if strings.TrimSpace(sessionID) == "" {
		return errors.New("sandbox: session ID required for input staging")
	}
	clean, err := cleanSessionInputPath(filePath)
	if err != nil {
		return err
	}
	handle, err := m.resolveSession(ctx, sessionID)
	if err != nil {
		return err
	}
	if err := ignoreExistingDir(m.client.MakeDir(ctx, handle, path.Dir(clean))); err != nil {
		return fmt.Errorf("sandbox: create input directory: %w", err)
	}
	if err := m.client.WriteFile(ctx, handle, clean, content); err != nil {
		return fmt.Errorf("sandbox: write session input %s: %w", clean, err)
	}
	return nil
}

// WriteSessionWorkspaceFile writes a model-authored file into the session's
// remote sandbox, provisioning the sandbox on first call. Paths must sit
// under /workspace and must not land in /workspace/input.
func (m *SessionBoundManager) WriteSessionWorkspaceFile(
	ctx context.Context, sessionID, filePath string, content []byte,
) error {
	if err := m.requireRemoteBackend(); err != nil {
		return err
	}
	if strings.TrimSpace(sessionID) == "" {
		return errors.New("sandbox: session ID required for workspace write")

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the wrapped error for permission vs. invalid-path causes.
  2. Ensure the target path resolves under the session input root and uses provider-safe characters.
  3. Verify the sandbox is still alive and re-resolve the session, then retry.
  4. Check provider disk/quota limits.

Example fix

// before
err := mgr.WriteSessionInputFile(ctx, sessionID, "../../etc/evil.txt", data)
// after
clean := path.Clean(filepath.Join("/inputs", attachmentName))
err := mgr.WriteSessionInputFile(ctx, sessionID, clean, data)
Defensive patterns

Strategy: validation

Validate before calling

// validate the attachment path before writing
func validInputPath(p string) bool {
    clean := path.Clean(p)
    return path.IsAbs(clean) && !strings.Contains(clean, "..") &&
        strings.HasPrefix(clean, "/inputs/")
}

Try / catch

if err := mgr.WriteSessionInputFile(ctx, sessionID, p, data); err != nil {
    if strings.Contains(err.Error(), "create input directory") {
        // sandbox may have expired mid-call: re-resolve and retry once
        return mgr.WriteSessionInputFile(ctx, sessionID, p, data)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Attachment path with unexpected characters or bad nesting, sandbox image restricting writes to the input root, provider quota exceeded, or race with sandbox cleanup.

Related errors


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