slimtoolkit/slim · error

failed to prepare artifacts env: %w

Error message

failed to prepare artifacts env: %w

What it means

Wraps an error returned by s.artifactor.PrepareEnv(cmd) during the standalone sensor's start-monitor flow. PrepareEnv sets up the artifact environment (directories, mounts, excludes) needed for monitoring; when that setup fails (I/O error, permission problem, invalid command parameters), run() publishes a StartMonitorFailed event and returns this wrapped error.

Source

Thrown at pkg/app/sensor/standalone/standalone.go:130

				State:     event.StateCmdStartMonCmdWaiting,
				Context: map[string]string{
					event.CtxCmdType: string(raw.GetName()),
				},
			})

		return fmt.Errorf("unexpected start monitor command: %+v", cmd)
	}

	if err := s.artifactor.PrepareEnv(cmd); err != nil {
		log.WithError(err).Error("sensor: artifactor.PrepareEnv() failed")
		s.exe.HookMonitorFailed()
		s.exe.PubEvent(event.StartMonitorFailed,
			&event.StartMonitorFailedData{
				Component: event.ComSensorCmdServer,
				State:     event.StateEnvPreparing,
				Errors:    []string{err.Error()},
			})
		return fmt.Errorf("failed to prepare artifacts env: %w", err)
	}

	origPaths, err := s.artifactor.GetCurrentPaths(s.mountPoint, cmd.Excludes)
	if err != nil {
		log.WithError(err).Error("sensor: artifactor.GetCurrentPaths() failed")
		return fmt.Errorf("failed to enumerate current paths: %w", err)
	}

	s.exe.HookMonitorPreStart()

	mon, err := s.newMonitor(
		s.ctx,
		cmd,
		s.workDir,
		s.del,
		s.artifactor.ArtifactsDir(),
		s.mountPoint,
		origPaths,

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Check the wrapped error and the sensor log line 'sensor: artifactor.PrepareEnv() failed' for the root cause.
  2. Verify the artifacts directory/mount point exists and is writable by the sensor process.
  3. Validate the StartMonitor command's fields (paths/excludes) are correct for your environment.
  4. Ensure sufficient disk space and correct container capabilities/mounts when running in containers.

Example fix

// before (docker run without writable volume)
docker run --rm sensor-image
// after
docker run --rm -v /path/to/artifacts:/artifacts:rw sensor-image
Defensive patterns

Strategy: validation

Validate before calling

if err := os.MkdirAll(artifactsDir, 0o755); err != nil {
    log.Fatalf("artifacts dir not creatable: %v", err)
}
if f, err := os.CreateTemp(artifactsDir, ".probe"); err != nil {
    log.Fatalf("artifacts dir not writable: %v", err)
} else {
    f.Close(); os.Remove(f.Name())
}

Try / catch

if err := sensor.Run(ctx); err != nil {
    if strings.Contains(err.Error(), "failed to prepare artifacts env") {
        log.Errorf("check mounts/permissions for artifacts dir: %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling run()/start-monitor when artifactor.PrepareEnv fails: e.g. the artifacts directory cannot be created, the mount point is invalid, the underlying cmd path is read-only, or cmd parameters (excludes/paths) are invalid.

Common situations: Running the sensor in a container without write access to the artifacts location; mount point not existing or not being mounted; disk full; misconfigured excludes causing path setup failures.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/7c0ac5dba7b04484. Report an issue: GitHub.