Tencent/WeKnora · error

remote sandbox: upload script %s: %w

Error message

remote sandbox: upload script %s: %w

What it means

ExecuteOnHandle uploads the script into the remote sandbox at a path under remoteScriptDir using client.WriteFile; if that upload fails the error is wrapped with the remote script path. The script never ran — this is purely an upload/transport failure against the sandbox handle.

Source

Thrown at internal/sandbox/remote_sandbox.go:150

			Timeout: effectiveTimeout(cfg, 0),
		}
		start := time.Now()
		execResult, err := s.client.Exec(ctx, handle, request)
		return remoteExecuteResult(execResult, err, time.Since(start)), nil
	}

	content, err := readScriptContent(cfg)
	if err != nil {
		return nil, err
	}
	scriptName := filepath.Base(cfg.Script)
	if scriptName == "" || scriptName == "." || scriptName == "/" {
		return nil, ErrInvalidScript
	}
	remoteScript := path.Join(remoteScriptDir, scriptName)

	if err := s.client.WriteFile(ctx, handle, remoteScript, content); err != nil {
		return nil, fmt.Errorf("remote sandbox: upload script %s: %w", remoteScript, err)
	}

	timeout := effectiveTimeout(cfg, 0)
	request := RemoteExecRequest{
		Command: getInterpreter(remoteScript),
		Args:    append([]string{remoteScript}, cfg.Args...),
		Stdin:   cfg.Stdin,
		Env:     cfg.Env,
		WorkDir: remoteScriptDir,
		User:    DefaultSandboxExecUser,
		Timeout: timeout,
	}

	start := time.Now()
	execResult, err := s.client.Exec(ctx, handle, request)
	duration := time.Since(start)
	return remoteExecuteResult(execResult, err, duration), nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the wrapped cause for connection vs permission vs size errors and address accordingly
  2. Re-acquire a fresh handle (or re-create the sandbox) if the old one expired, then retry ExecuteOnHandle
  3. Reduce script size or split the script if the upload hits payload limits
  4. Avoid disposing handles concurrently while an ExecuteOnHandle is in flight

Example fix

// before
res, err := sbx.ExecuteOnHandle(ctx, handle, cfg)
// after
res, err := sbx.ExecuteOnHandle(ctx, handle, cfg)
if err != nil && strings.Contains(err.Error(), "upload script") {
    if fresh, ferr := s.client.Create(ctx, s.createRequest); ferr == nil {
        return sbx.ExecuteOnHandle(ctx, fresh, cfg)
    }
}
Defensive patterns

Strategy: fallback

Validate before calling

if content, err := os.ReadFile(cfg.Script); err != nil || len(content) > maxUploadSize {
    return fmt.Errorf("script unreadable or too large")
}

Try / catch

res, err := sbx.ExecuteOnHandle(ctx, handle, cfg)
if err != nil && strings.Contains(err.Error(), "upload script") {
    return recreateHandleAndRetry(ctx, cfg)
}

Prevention

When it happens

Trigger: ExecuteOnHandle called with a script whose content WriteFile cannot persist: connection dropped mid-upload, payload too large, permissions on the remote path, or the handle was already disposed/expired.

Common situations: Long sessions where the remote sandbox was reaped mid-run; large skill scripts hitting size limits; flaky network between runner and sandbox; concurrent disposal of the same handle.

Related errors


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