Age old question will be met with age old replies; take breaks, try to avoid botting during working hours, consider premium/private scripts, thinking about how long and at what time you bot, consider proxies to avoid chainbans and the like.
From personal experience a good script goes a long way, so I usually find a script that works well and then use a more cautious approach to botting, especially when running smallers farms, as each account is more important and bans set you further back.