I'm not fully aware of the legal aspect of this. But as for my knowledge, working for two companies is not illegal as long as you're not involved in any illegal work.
However, you may also consider the employment agreement of both companies. Because, some companies restrict an employee working for another company by the employment agreement. Some companies do not enforce such limitation, but you're not allowed to work for a competitor organization. And that is highly unethical of you doing so as well.