-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpty.py
More file actions
35 lines (28 loc) · 865 Bytes
/
pty.py
File metadata and controls
35 lines (28 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from leap0 import Leap0Client, PtyConnection, PtySession, Sandbox
def main() -> None:
client = Leap0Client()
sandbox: Sandbox = client.sandboxes.create()
try:
session: PtySession = sandbox.pty.create(
session_id="demo-terminal",
cols=120,
rows=30,
cwd="/home/user",
)
connection: PtyConnection = sandbox.pty.connect(session.id)
try:
connection.send("pwd\n")
print(connection.recv().decode("utf-8", errors="replace"))
finally:
connection.close()
finally:
try:
sandbox.delete()
finally:
client.close()
if __name__ == "__main__":
main()