How to build arbitrary code without risking the server?

So I’m creating a server that is in charge of building code. This server should be able to run arbitrary building scripts without those being able to harm the server. For example by modifying configuration files, tampering binaries or stealing secrets in home.

Do you have any tips for this? Thanks in advance.