Thanks for the suggestion! I originally thought about this approach. But because I would like to create this for large number of machines (around 100) the number of groups can become quite large (combination of 10 out of 100 =17310309456440!!).
I debugged it and it seems like the limit for the number of cgroups exceeds the current user limit. I guess this may be related to the dist.new_group and repeated creation of groups.
The error printed in the kernel messages is printed below:
cgroup: fork rejected by pids controller in /user.slice/user-1000.slice/session-3.scope

I wish there was a method to delete the groups in order to avoid this problem.