"In the bag" is an idiom that means that something is very nearly guaranteed. It is typically used in a scenario where someone asserts that a certain event, usually positive, is bound to happen, or at the least, very likely to happen. This can refer to anything from winning sports games to securing a date with a love interest, or many other achievements. This idiom is sometimes considered slang and may not be appropriate for use in formal writing, depending on the audience. Despite occasionally being labeled as slang, it is not a vulgar term at all and is frequently used in casual writing and everyday speech.
An example of one use of this idiom would be if someone were to bolster a friend's confidence by saying, "You did a really nice job with your interview this afternoon; let's go celebrate now, because that new job is clearly in the bag!" This idiom is essentially an assumption that all will go perfectly as planned, which often allows the individual in question to relax and stop worrying about a certain thing, such as in the previous example, or even to stop feeling an urgent need to prepare for a certain event. For example, "You have been studying all week, you should really relax a little bit and come to the party, because I am sure you have that final exam in the bag by now," is an assurance that the individual will surely perform well enough to stop being stressed out over doing badly on a test that he or she is certainly prepared for. In some cases, this can definitely lead to a false sense of security and disappointment when it turns out that the individual may not have had his or her performance "in the bag" after all.
Occasionally, this idiom is confused with the similar-sounding idiom "let the cat out of the bag," especially by people who speak English as a second language and may not be familiar with many English idioms. Since letting the cat out of the bag means revealing a secret, it is commonly misinterpreted that when something is "in the bag," it is a secret. This is not actually a correct usage of the idiom "in the bag," though to those just learning English, that definition may seem to make logical sense.