What is cloaking?
Cloaking in SEO is a practice of presenting different content/URLs or information to users from what is presented to search engine crawlers (i.e. spiders or bots) to improve a website’s search engine rankings for certain keywords.
Serving up different results based on user agent may cause your site to be perceived as deceptive and removed from the Google index.
The search engine keeps updating their algorithm frequently and if you use cloaking, they will sooner or later find it out and may permanently ban your website from being indexed.