Consider box A and B together as comprising a system. See the diagrams below. You apply a force to box A in contact with box B, call it $F_{ext}$. At the interface between the boxes Box A applies a force to Box B, call it $F_{AB}$ and per Newton's third law box B applies an equal and opposite force on Box A, call it $F_{BA}$. The equal and opposite action/reaction forces $F_{AB}$ and $F_{BA}$ are internal to the system and cancel each other
But the force you apply, $F_{ext}$ is external to the system of the two boxes. Since the boxes are on a frictionless surface there is no external friction force acting on the boxes opposing your applied force.
But you also need to consider that when you push on the two boxes they together push back on you with an equal and opposite force again per Newton's third law. In order for that reaction not to cancel your externally applied force, there needs to be another external force, the static friction force between you and the surface, to oppose the reaction force of the two boxes. Imagine trying to move the boxes if you were standing on ice. As long as your external force does not exceed the maximum static friction force between your feet and the surface, you will not slip.
If you look at the bottom diagram showing all the forces you can see that they all cancel each other, except for your externally applied force to the two boxes, and thus
$$F_{ext}= (M_{A}+ M_{B})a$$
As a matter of fact, it is the static friction force between your feet and the surface that is responsible for you being able to accelerate the boxes.
Hope this helps.