>Would it actually be legal to alternate between Andorra and France or Spain?

Yes, on condition that when entering Andorra you have a Schengen Area **exit** stamp and when leaving Andorra have a Schengen Area **entry** stamp.

As far as the Schengen Border Code is concerned, it is the proper entry/exit stamps that counts (assuming you don't require a visa) for short term stays.

Without the entry/exit stamps you are assumed to have overstayed, unless you can prove otherwise.


---
**Sources**:
- [How to Get a Residence Permit in Andorra | Andorra Guides](https://andorraguides.com/residency/how-to-get-residence-permit-in-andorra/)
   - [Décret n° 2003-740 du 30 juillet 2003 portant publication de la convention entre la République française, le Royaume d'Espagne et la Principauté d'Andorre relative à la circulation et au séjour en Principauté d'Andorre des ressortissants des Etats tiers, signée à Bruxelles le 4 décembre 2000 (1) - Légifrance](https://www-legifrance-gouv-fr.translate.goog/jorf/id/JORFTEXT000000229407?_x_tr_sl=fr&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=sc)
   >**Section 4**   
   >...   
   >The regime for entry and movement in France and Spain for foreigners holding an **Andorran residence permit** is identical to that which applies to foreigners holding a French or Spanish residence permit.
   >>Google Translate Original text
- [Andorra Schengen Visa Explained | Andorra Guides](https://andorraguides.com/visa/schengen/)