As above. Our ship departs Livorno at 1800.
What exactly are you asking? Do you want to just know if there are public buses and trains between these places so you can visit them independently?
Trains run frequently between all these places. They are Regionale trains, don't require advance reservations, and are inexpensive. Look on the Trenitalia website for times and fares.
Buses take longer and aren't as frequent.
When does the ship come ashore? Wouldn't the cruise company provide its own tour to Pisa? This would be more expensive, but would eliminate any risk of getting stuck if you are delayed somehow. Transport in Italy is reliable, but train breakdowns and traffic hold-ups can happen anywhere...
See the OP's other post; this question appears to have already been answered:
https://community.ricksteves.com/travel-forum/italy/lucca-and-pisa-from-livorno
And also a third time, two months ago. If the OP doesn't have confidence in the answers, it might indeed be better to take an organised excursion.
We did a cruise that ported in Livorno for a day and took a tour of Pisa and Lucca. It was excellent. We had been to Pisa over 25 years ago when we lived in Germany and drove to Italy. As I recall the Leaning Tower and sanctuary are not near the town center of Pisa. Not sure doing Pisa (leaning tower) and Lucca would be wise on your own.