How to limit holdout to one or more objects?
Using view layers:

Setup your scene with 3 collections:

One for the objects that won't be masked

One for the objects to mask

One for the holdout object


Then create a layer for the &quot;no hold out&quot;:


No hold out collection is rendered

Holdout collection is indirect only

Holdout object is disabled


And a layer for the hold out:


No holdout part is indirect only

Holdout part is rendered.


In the compositor:

The hold out layer is alpha over for either alpha parts of the holdout layer or for the parts where holdout depth is greater than the no holdout one.
All is rendered with a transparent film.