First of all, you only explicitly define two items
At the start, you have:
The bag-with-a-button in the handbag.
After shopping, I assume that you have expanded the bag-with-a-button and it is now holding groceries.
It makes no sense that you would be able to put the expanded bag-with-a-button (and its groceries) back into the handbag. However, the reverse could be true.
Assuming it is, you would leave the store with:
The bag-with-a-button (and its groceries) in the handbag.
In both scenarios, all you have is:
A bag in a bag.
So, I don't see where the third "bag" is coming from.
Even if I guess that you may be referring to the bag-with-a-button as a "bag in a bag," I would write that out as the "bag-in-a-bag" and we would end up with one of the following situations, depending on if you were arriving at or leaving the store:
- The bag-in-a-bag in the bag.
- The bag in the bag-in-a-bag.
But let's put aside the question of where all of your "bags" are coming from, and assume that there actually is a third or even a fourth.
I can think of no possible logical sense in which any of these bags could be placed "inside itself."
The handbag in the bag-with-a-button in the handbag.
Or (after dropping unique names):
The bag in the bag in the bag.
This construction, while valid in terms of syntax, is not possible from a practical standpoint. (Unless in a thought experiment or some science fiction or fantasy story.)
While I can form a grammatical sentence that repeats in a bag as many times as I want, it would be nonsensical if one of those instances referred back to itself.
However, if you can expand each instance of "the bag" with a unique name and if you can use all of those unique names in a sentence only once, then it is both grammatical and semantically correct (even if confusing).