They definitely work.
Sram and Shimano are almost totally interchangeable, if you keep to the same gear amount of indexing (The cassettes and shifters have to be the same as in all: 8, 9, or 10.)
But they fall into two main groups:
9 and 10 speeds. everything interchangeable between brands
7 and 8 speeds. everything interchangeable between brands
front mechs (too hard to type derailleur) are totally interchangeable only depending on pull direction.
You can’t mix 9-10 with 7-8 speeds as they are completely different in size. (teeth size and spacing).
An important point to remember on rear mechs is the hanger distance and the cage length.
The hanger distance is important so that the rear mech is far enough away from the smallest tooth on the cassette for it to clear. This is bike specific.
The cage length is important so that it can take up chain slack. On MTB nearly all cages are long as they are used on bikes with three front chain wheels although not always called “long”. So as a rule of thumb, a rear mech used on a bike with three chain wheels of 9/10 speed are interchangeable. A rear mech used on a bike with two chain wheels of 9/10 speed are interchangeable. The same goes for the 7/8 speed group.
Road bikes call this triple or compact and Shimano say they’re cages are GS and SS (GS: medium but is actually large in old money)
Obvious to say that manufactures design their gear to run on their own equipment and thus will get best result if you don’t mix and match, but you would hardly notice the difference.
I personally stick to Shimano, but I have no good argument as to why, just a personal preference
I have three bike like this all interchanged at some point with Sram and Shimano, Mostly because of cost or what was available as a spare at the time.