anomalyco/sst · error

failed to copy binary: %w

Error message

failed to copy binary: %w

What it means

During the Rust runtime build, after `cargo` produces the compiled binary, SST copies it to the function output directory as `bootstrap`. This error wraps any `io.Copy` failure between the source binary and the destination file — typically a disk-level or I/O problem, not a compile error (cargo failures fail earlier with their own message).

Source

Thrown at pkg/runtime/rust/rust.go:163

	if err := os.MkdirAll(filepath.Dir(out), 0755); err != nil {
		return nil, fmt.Errorf("failed to create output directory: %w", err)
	}

	source, err := os.Open(binary)
	if err != nil {
		return nil, fmt.Errorf("failed to open source binary: %w", err)
	}
	defer source.Close()

	destination, err := os.Create(out)
	if err != nil {
		return nil, fmt.Errorf("failed to create destination file: %w", err)
	}
	defer destination.Close()

	if _, err := io.Copy(destination, source); err != nil {
		return nil, fmt.Errorf("failed to copy binary: %w", err)
	}

	if err := os.Chmod(out, 0755); err != nil {
		return nil, fmt.Errorf("failed to make binary executable: %w", err)
	}

	return &runtime.BuildOutput{
		Handler:    "bootstrap",
		Sourcemaps: []string{},
		Errors:     []string{},
		Out:        root,
	}, nil
}

func (r *Runtime) Run(ctx context.Context, input *runtime.RunInput) (runtime.Worker, error) {
	cmd := process.Command(
		filepath.Join(input.Build.Out, input.Build.Handler),
	)

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Free up disk space (`df -h`) and clear large `target/` directories with `cargo clean`, then rebuild
  2. Re-run `sst build` / `sst dev` — transient I/O errors often clear on retry
  3. Check for concurrent SST/cargo processes on the same project and stop them
  4. Verify the output filesystem is writable and not full or mounted read-only
Defensive patterns

Strategy: retry

Validate before calling

// before deploy: check free space and the built binary
const stat = fs.statSync(path.join(crateRoot, "target", "lambda", name, "bootstrap"));
if (stat.size <= 0) throw new Error("cargo produced an empty binary");
const free = checkDiskSpace(process.cwd()); // e.g. via 'check-disk-space' pkg
if (free.free < 1024 * 1024 * 1024) throw new Error("need >=1GB free disk space");

Try / catch

try {
  await run("sst", ["build"]);
} catch (e) {
  if (/failed to copy binary/.test(String(e))) {
    await exec("cargo", ["clean"]);
    await run("sst", ["build"]); // retry after freeing space
  } else throw e;
}

Prevention

When it happens

Trigger: `io.Copy(destination, source)` returns an error while copying `target/{debug|lambda/<name>}/bootstrap` to the function's `.sst` build output — e.g. disk full (ENOSPC), source binary deleted mid-read, destination file truncated, or a filesystem/EFS error.

Common situations: Ran out of disk space in `~/.cargo`/`target` heavy projects; concurrent `sst build` runs racing on the same target directory; container/CI with small ephemeral disks; antivirus or file watchers locking the file during copy.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/ae958542bbf9e638. Report an issue: GitHub.