Skip to content

Commit 39a2228

Browse files
author
Eric Snow
authored
Add a script to run scripts/modules in an isolated way. (microsoft#10670)
For microsoft#10681 We'll use this for our security hardening.
1 parent f1a0b36 commit 39a2228

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎pythonFiles/pyvsc-run-isolated.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
if __name__ != "__main__":
5+
raise Exception("{} cannot be imported".format(__name__))
6+
7+
import runpy
8+
import sys
9+
10+
# We "isolate" the script/module (sys.argv[1]) by
11+
# deleting sys.path[0] and then sending the target
12+
# on to runpy.
13+
del sys.path[0]
14+
del sys.argv[0]
15+
module = sys.argv[0]
16+
if module.endswith(".py"):
17+
runpy.run_path(module)
18+
else:
19+
runpy.run_module(module, alter_sys=True)

0 commit comments

Comments
 (0)