Would it be acceptable to occasionally sleep at the lab? I'm currently an undergrad, and work as a researcher in an EECS lab. Recently, I discovered a novel application to work on, and so for the last few weeks I've been staying at the lab late almost every day, leaving at midnight or later. Since I live in a dorm on the opposite end of campus, I usually don't get to sleep until around 2-3 AM. In the morning I need to be up and in class by 8-9 AM (depending on the day), in a building that happens to be right next to the lab.

Would it be acceptable to set up a foldable cot at night (leave it under my desk during the day) and sleep at the lab occasionally? I'm usually the last person at the lab at night. If it cultural context matters, I work at a research university in California (US).

EDIT

The lab is mostly composed of graduate students and professors, so they usually maintain a regular 9-5/5:30 schedule at the lab (minus office hours and lectures). As one of a small handful of undergrads, I'm usually there between 4 (when class ends) and well after everyone else leaves. In some cases, graduate students will sleep in the graduate student lounge just outside the lab proper (still part of the lab IIRC).
Ask your supervisor. If your PI supervisor controls the space and gives you permission, there shouldn't be any problem for you.

I've seen situations where there are experiments that need to be babysat over long periods and researchers bring cots into the lab so that they can devote more time and provide more frequent checkups than would be possible otherwise.

Of course, if you are homeless and living in the lab for some longer period of time to avoid paying rent somewhere else, that seems like a much bigger problem. Honestly though, I've seen that done as well. The OK-ness and consequences of sleeping your lab will depend on the local culture, rules, and laws. If you ask a supervisor, it will be their responsibility to make that call.