Lenin had been in exile from the Russian Empire since December 1907. (Prior to that he had been in Finland, but that had become too unsafe despite its autonomy.) When the war broke out in 1914, he was in Poronin, Galicia, not far from the Russian border. As a Russian national in a country at war with Russia, he faced some problems:
"There was a natural spy mania, even among those simple mountain people who could not quite understand what it was all about. An obliging peasant informed the police that the mysterious Russian gentleman in Poronin would often sit on a hill, undoubtedly making sketches of strategic objectives. A police search in the peasant hut rented by the Ulyanovs turned up a paper full of figures, undoubtedly a ciphered message for the invading Cossacks (it was actually a manuscript on the agrarian question, full of statistics. Even so, the police were lackadaisical in the typical manner of Hapsburg officialdom. The 'spy' was told to turn himself in next day to the police in the nearest town. There he would presumably be questioned and interned by people who knew more about such things than a simple village constable.
"The prospect of spending the war as an internee did not enchant Lenin. He called for assistance from Jacob Fuerstenberg-Hanecki, a Polish-born member of his Bolshevik entourage, then, fortunately, in Poronin… [Hanecki] mobilized his acquaintances among the Polish Socialists in Galicia to intervene on Vladimir Ilyich's behalf. On August 8 the latter turned himself in to the authorities in the town of Novy Targ, where he was lodged in jail.
"Despite his predicament he was in excellent spirits. It was obvious that his imprisonment would not be long; influential voices were being raised on his behalf. Hanecki contacted the leaders of the Polish Socialist Party, Daszynski and Marek. In Lenin's eyes they represented the most degenerate and chauvinist type of socialism. In 1920 Daszynski would be the vice-premier of the Polish government whose armies routed the Bolsheviks on the approaches to Warsaw. But their ideological differences did not keep the Poles from intervening vigorously on Lenin's behalf. They pointed out the full absurdity of accusing this inveterate revolutionary of being a spy for the Tsar. Krupskaya wired to the Austrian Socialist Victor Adler to plead with the Imperial authorities in Vienna, one of the relatively rare documents signed with her married name, Ulyanova. Much later on, Hanecki was to write unimaginable nonsense as to what arguments were used to procure Lenin's release: the Austrian authorities were fearful of holding a man who was beloved by the Russian working masses. Actually, as his own account of 1924 makes clear, the Poles felt duty-bound to help a fellow Socialist. The Austrian Minister of the Interior was told that Ulyanov and his party were enemies of Tsarism, and very likely to render indirect services to the cause of the Central Powers. After ten days Lenin was freed, and in September he was in Switzerland. From Zurich he sent his thanks to "Highly Esteemed Comrade" Adler. Not for the last time, he had been bailed out by the 'opportunists' and 'Socialist chauvinists'...." Adam Ulam,
The Bolsheviks, pp. 300-301
https://books.google.com/books?id=dN5V8WX5WP0C&pg=PA301
Was Lenin in any actual danger? IMO the only (slight) risk was that he would be lynched by local peasants before the authorities could intervene. Once he was in custody, he was safe--the Austrian Socialists were sure to make clear to the government that it was absurd to see Lenin as pro-Russian in the war, and that he should be released and allowed to live in a neutral country.
The other theoretical danger was that the Russian offensive in Galicia would capture Lenin, but it is very doubtful that they would reach Poronin in time for that. If they did somehow manage to capture him, serving in the military would be the least of his worries...