URL.getSalesforceBaseUrl().getHost()) will give the URL of Salesforce instance.
Sample Code:
public Boolean isSandbox() {
return URL.getSalesforceBaseUrl().getHost().left(2).equalsignorecase(‘cs’);
}
Another way to find is
SELECT Id, IsSandbox, InstanceName, Name FROM Organization limit 1
Cheers!!!