Hey there
That’s a fairly broad question.
Having your environment info, server logs and or desired capabilities would help tremendously.
A big reason for flakiness stems from delays in the network, os, or elsewhere.
It’s best to take the time to understand and implement explicit waits in your script. There’s quite a few posts in this forum. This one may help get you started:
Best of luck