It depends on your current status in Canada. If you have valid status in Canada (e.g. visitor, student, worker), you can certainly apply.
If you do not have valid status in Canada either due to falling out of status or being a refugee applicant, then to the best of my knowledge it is not possible. See OINP site details regarding status in Canada for applicants:
https://www.ontario.ca/page/ontarios-express-entry-human-capital-priorities-stream
Legal status in Canada (if applicable)
If you are applying from within Canada, you must have legal status (visitor record, study permit, or work permit) at the time you apply and should maintain that status until the time of nomination.