Good that you have found this way. That’s what I wanted to explain for the Desktop use case.
When you use python you can use snappy. This helps reading the data.
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/19300362/How+to+use+the+SNAP+API+from+Python
However, the simplest way to do on a batch of products is probably to use gpt. There are two wiki pages available which explain how to do it. They are linked here:
https://senbox.atlassian.net/wiki/spaces/SNAP/pages/70503053/Processing
For your use case, you need 3 operators chained in a graph.
I’ve attached a template. shapefileExtraction.xml (1.5 KB)
In the first step, the data is tailored to the bounding box. Here I just added a random rectangle.
In the second step, the shapefile is imported and in the last step, the data outside of the shapefile is masked.
Unfortunately, this approach does not export only the pixels covered by your shapefile but always the bounding box. Especially when exporting to CSV/ASCII format the amount of data is huge.