a Middle English merger of Old English in (prep.) "in, into, upon, on, at, among; about, during;" and Old English inne (adv.) "within, inside," from Proto-Germanic *in (source also of Old Frisian, Dutch, German, Gothic in, Old Norse i), from PIE root *en "in." The simpler form took on both senses in Middle English.
Sense distinction between in and on is from later Middle English, and nuances in use of in and at still distinguish British and American English (in school/at school). Sometimes in Middle English shortened to i.
The noun sense of "influence, access (to power or authorities)," as in have an in with, is first recorded 1929 in American English. to be in for it "certain to meet with something unpleasant" is from 1690s. To be in with "on friendly terms with" is from 1670s. Ins and outs "intricacies, complications of an action or course" is from 1660s. In-and-out (n.) "copulation" is attested from 1610s.
element meaning "into, in, on, upon" (also im-, il-, ir- by assimilation of -n- with following consonant), from Latin in- "in," from PIE root *en "in."
In Old French (and hence in Middle English) this often became en-, which in English had a strong tendency to revert to Latin in-, but not always, which accounts for pairs such as enquire/inquire. There was a native form, which in West Saxon usually appeared as on- (as in Old English onliehtan "to enlighten"), and some of those verbs survived into Middle English (such as inwrite "to inscribe"), but all now seem to be extinct.
Not related to in- (1) "not," which also was a common prefix in Latin, causing confusion: to the Romans impressus could mean "pressed" or "unpressed;" inaudire meant "to hear," but inauditus meant "unheard of;" in Late Latin investigabilis could mean "that may be searched into" or "that cannot be searched into." Latin invocatus was "uncalled, uninvited," but invocare was "to call, appeal to."
The trouble has continued in English; the hesitation over what is meant by inflammable being a commonly cited example. Implume (1610s) meant "to feather," but implumed (c. 1600) meant "unfeathered." Impliable can mean "capable of being implied" (1865) or "inflexible" (1734). Impartible in 17c. could mean "incapable of being divided" or "capable of being imparted." Impassionate can be "free from passion" or it can mean "strongly stirred by passion." Inanimate (adj.) is "lifeless," but Donne uses inanimate (v.) to mean "infuse with life or vigor." Irruption is "a breaking in," but irruptible is "unbreakable."
In addition to improve "use to one's profit," Middle English also had a verb improve meaning "to disprove" (15c.). To inculpate is "to accuse," but inculpable means "not culpable, free from blame." Infestive has meant "troublesome, annoying" (1560s, from infest) and "not festive" (1620s). In Middle English inflexible could mean "incapable of being bent" or "capable of being swayed or moved." In 17c., informed could mean "current in information," formed, animated," or "unformed, formless" ("This was an awkward use" [OED]). Inhabited has meant "dwelt in" (1560s) and "uninhabited" (1610s); inhabitable likewise has been used on opposite senses, a confusion that goes back to Late Latin.
In Old French and Middle English often en-, but most of these forms have not survived in Modern English, and the few that do (enemy, for instance) no longer are felt as negative. The rule of thumb in English has been to use in- with obviously Latin elements, un- with native or nativized ones.