From GlobalSign: Code Signing FAQ:
Where an SSL certificate for a website would contain an extended key usage of Server Authentication showing it can be used to identify a server, a code signing certificate has an extended key usage of Code Signing to indicate it may be used to sign code.
Thus for code signing you need an extended key usage of Code Signing while for a web server instead a key usage of Server Authentication. And for certificate signing the basic constraints would need to allow the certificate to be used as a CA. By creating certificates which differ in these settings and also have these settings marked as critical so that they are not ignored you can get the appropriate restrictions.