Yes, you can work remotely as an employee of a foreign country living in Portugal on a D7 visa.