The container will not have a kthreadd, which is always pid 2:
[[ $(ps -p2) ]] && echo host || echo container
This will not work if either:
hidepid=2
these would be somewhat obscure conditions.