In most workplaces, there’s someone who brings the negative energy and drama, like a lot of bad weather. Maybe they’re unaware of their behavior, or worse, enjoy pushing other people’s buttons. Either way, a difficult teammate can quickly sink office morale and create a lot of stress.

With other types of work stressors—a looming deadline or big presentation, for instance—you can take steps to manage them: Breaking down a big project into smaller tasks; taking some deep breaths before your meeting. Dealing with a toxic co-worker is a different type of challenge because you can’t control someone else’s behavior.

You can, however, control how you choose to respond to them. According to Travis Bradberry, Ph.D., co-author of “Emotional Intelligence 2.0,” “To deal with difficult people effectively, you need an approach that enables you to control what you can and eliminate what you can’t.” 

Here’s how resilient people do it:

1.They Set Boundaries

Complainers and those who can’t wait to share bad news will take a toll on your emotional and physical well-being. To protect yourself, establish boundaries and make your expectations clear

With complaining, ask how they intend to fix the problem. That will either quiet them down or redirect their focus on a solution, says Bradberry. Or suggest they talk to their manager or someone who can solve their issues.

When it comes to gossip, stop it in its tracks with a simple, “I’m not comfortable talking about our colleague.” If that feels a little awkward, try changing the subject. For example, if the topic is a coworker’s bad behavior at last week’s happy hour, you can smoothly transition the conversation to the great place you stumbled on for the next team outing.

2.They’re Emotionally Aware

Maintaining emotional distance requires awareness. You can’t stop someone from pushing your buttons if you don’t recognize when it’s happening—whether it’s the overly dramatic person who gets under your skin or the colleague who takes credit for your idea at the team meeting. 

Emotional awareness comes down to noticing our patterns of thought and emotion, and then identifying when we have reactions that are counterproductive. Then we have the opportunity to pause and make decisions about how we want to respond. For example, when you catch yourself getting angry, you can slow yourself down (rather than reacting in the heat of the moment), perhaps notice that it’s more about them than you, and choose how you want to respond. 

Another trick for keeping your emotional distance: Stanford professor and organizational psychologist Robert Sutton suggests pretending you’re an anthropologist studying a strange species—how they act and speak and how others respond. “What a bizarre way of communicating,” you might think. This way, you’re less likely to take what they do or say personally.

3.They Focus on the Positive

If you’ve ever come home from work and spent the entire evening obsessing over a co-worker’s remark or rehashing a conversation, then they’re intruding on your personal space. Amy Morin, LCSW, author of the book “13 Things Mentally Strong People Don’t Do,” says the minute you catch yourself doing this, take action: Wash the dishes, watch a movie, call a friend, go for a walk—whatever it takes to change the channel in your brain.

Where you focus your attention determines your emotional state. When you fixate on someone’s challenging behavior, you prolong negative emotions and stress. If you redirect your attention either to an enjoyable pastime or figure out how to address the problem, you break the chain of thinking.

4.They Practice Healthy Coping Skills

Difficult co-workers can drain your battery; and you can’t stay mentally strong if you’re sleep-deprived, fueling up on junk food, or taking up other less-than-healthy habits.

Getting proper sleep, in particular, helps you function at your best. When you’re well-rested you’ll think more clearly, improve your problem-solving ability, feel more positive, and be better able to deal with challenges. Your self-control, attention, and memory suffer when you don’t get enough. In fact, sleep deprivation raises stress hormone levels on its own, even without a stressor present.

Focus on staying strong and doing your best work. Toxic people can only get the best of you if you let them.