Working from home definitely has its perks: working in your pajamas, enjoying a commute-free day, stopping for a snack whenever you like. It seems like a dream situation — but the reality can be a lot less glamorous.

When you work at home, the line between work and your personal life blurs. For example, in the middle of the day, you may feel an intense urge to tackle that pile of laundry even though you should be working. Likewise, an email may pop up off-hours and if you’re hanging out at home, you might sign onto your computer to take care of it.

Working at home can affect your physical health, too, if you don’t have the proper setup. Here’s how to protect both your health and your sanity.

Get ergonomic

When working at home, any part of your house or apartment can turn into your office. The couch? Yep. The bed? Sure. But this may cause more pain than gain. As awesome as it seems to work from these comfy spots, it’s not very ergonomic.

In order to have a workspace conducive to working rather than napping, look into getting a desk and office chair that fits your body and your needs. Having a proper setup not only boosts your productivity, but it can also prevent issues like neck strain, headaches and carpal tunnel syndrome, according to the National Institutes of Health (NIH).

The NIH suggests getting an adjustable chair — so, not the pretty wooden chair you may have bought with your desk, or your kitchen table chair. And don’t forget a wrist rest in front of your keyboard. The Occupational Safety and Health Administration recommends using a soft but firm one to support repetitive hand motions and help avoid carpal tunnel syndrome. Read our guide to setting up an ergonomic office for more details.

Related: 5 Easy Workout Moves You Can Do at Your Desk

Shed the right light

If you find yourself working at night, be careful or your sleep may suffer. Exposure to light from electronics can disrupt melatonin production, preventing you from feeling sleepy, according to the National Sleep Foundation. The American Medical Association recommends using dim red lighting in the bedroom at nighttime. You can purchase red light bulbs at hardware stores.

f.lux, a software that dims the light of your computer, adapting it to the time of day. So if you’re up late working, your screen won’t have that burst of blinding blue but a more reddish hue, which is easier on the eyes and better for your sleep.

Of course a third option is to simply put your electronics away well before bedtime.

Stay focused

Even though technology can be a distraction, it also can be the solution to maintaining your focus on work. These apps can keep you working in the zone.

FocusBooster helps you maximize productivity with the Pomodoro technique, which encourages working in increments with frequent breaks. The app uses a timer set to 25 minutes, then calls for a five-minute break. (You can adjust it to use longer blocks of time.)

SelfControl is an app for Mac users that allows you to block distracting websites for a certain period of time. If you constantly find yourself falling down the rabbit hole of social media, you can use this app to block those sites when you really want to focus and get to work. If you don’t have a Mac, you can use the Google Chrome extension StayFocusd.

Related: 9 Tech Habits that Can Wreck Your Body (and How to Break Them)

Set boundaries

If you work from home, family members may see you and think you’re available for this or that, especially if you have kids or a partner who also works from home.

Holly Johnson, a freelance writer and mother of two who works at home, discovered the importance of setting expectations. “There are times when I need to work when everyone is home, and I simply go in my office and close the door. My family understands that this is my "real job" so there is never any issue. You just have to treat at-home work like you would any regular job,” Johnson says.

In addition to setting expectations with your family, set a regular schedule for yourself. Johnson says, for example, she schedules her work day around her children’s daycare and school schedules. This can help you maintain your boundaries and protect your sanity — so that you can enjoy the best of both worlds, without compromising your health.

Do you have any tips to add? Feel free to post in the comments section. 

Melanie Lockert is a freelance writer and blogger who is passionate about empowering others to take control of their finances.