Hi
I know it is nearly a year later, but your code is not doing what you think it is doing.
Box4 does the following logically:
It creates a component def
Then you add 1 face to it and pull the face to make a block
then you add this component as an instance
then you add another face to it and pull it making block 2
then you add another instance. But you also update the original instance to now have two blocks
and so on
if you set it to have 3 by 3 blocks you get 9 components all the same with each nine pulled faces inside it. The inside blocks are not component instances, the are merely blocks (pulled faces) inside the component.
If you select the block at the end of the process and move it you will see there are more blocks underneath it.
If you wanted to do what you intended, you needed to create a new component def each time you enter the upto loop.