Varenna does not have a ticket machine or sales agent at the station. You can buy tickets from a travel agency near the station, when they are open, but it is easiest to just buy them online from Trenitalia. The tickets cost only 8 euros. You must validate this ticket (or “check in” with Trenitalia using the app, or a link they send to your email, before you board the train.
In June there will be track work on the line going to Tirano, so the train will take you as far as Colico where you change to a bus to Tirano (included in the ticket price). If you prefer to take a taxi from Varenna to Colico, you can board the bus there with the ticket you bought online. The ticket for that journey is €6,60. Make sure you check the current schedule on Trenitalia so you can time your journey to Tirano to meet a Swiss train on the Bernina route, whether it is a Bernina Express train with panoramic cars, or a regular train on the same route. With the bus link, it is a bit over 2 hours from Varenna to Tirano.