Multi tenacy process automation

Hello friends

I know the two methods that can create multi tenancy setup DNS or port based

but i want to use a automated method like erpnext demo using when creating demos to

from the backend not using CLI or becnh how can i do this or custom script that can make it

hope you help