Loki is a bad boy. But sometimes, he's nice. However, he is really only nice to his brother Thor when he wants something from him. Will Loki turn on his brother in "Infinity War?" He's worked with Thanos before, so it's possible.
It's also very possible that Loki took the Tesseract from Asgard, which he could give to Thanos to get on the big bad's good side.
No matter what happens, considering his behavior in "The Avengers," it's unlikely the team will be okay with him fighting by their side.