At SJO, stay airside—small airport where security rechecks and traffic limit exit options.
A 3-6 hour layover in San Jose is doable since the airport is only 18km from downtown. Taxi to the city center costs $12-16 and takes 20-30 minutes. Head directly to the Central Market (Mercado Central) for a traditional casado lunch, or walk to Barrio Amon for the Victorian architecture. Allow 75 minutes to return to the airport.
Six to ten hours lets you see the best of San Jose without rushing. Start at the National Theater (Teatro Nacional) on the Plaza de la Cultura - the interior is open for a small fee and the architecture is remarkable. Walk through Barrio Amon for colonial mansions and boutique cafes. The Gold Museum (Museo del Oro Precolombino) beneath the Plaza is free for the permanent collection and covers Mesoamerican gold artifacts well. Mercado Central for lunch: fresh fruit, gallo pinto, and excellent cheap coffee. The La Sabana park on the west side of the city is a good place to walk. Return 90 minutes before your flight.
With 10+ hours, consider a day trip. The cloud forest at San Gerardo de Dota (2 hours from the airport) is reachable for birdwatching - the resplendent quetzal is sometimes spotted at altitude. Irazu Volcano National Park (1.5 hours) has a dramatic crater lake visible on clear days. Closer in, the artisan town of Sarchi (1 hour) is Costa Rica's craft center for painted oxcart souvenirs. If you stay in the city, the MADC contemporary art museum in Barrio Amon is small but excellent. Soda Tapia near the airport has been serving the best traditional casados in the city since 1956.