MCPcopy Create free account
hub / github.com/e2b-dev/desktop / main

Function main

examples/basic-python/main.py:45–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43 webview.start()
44
45def main():
46 print("> Starting desktop sandbox...")
47 desktop = Sandbox.create()
48 print(" - Desktop Sandbox started, ID:", desktop.sandbox_id)
49
50 width, height = desktop.get_screen_size()
51 print(" - Desktop Sandbox screen size:", width, height)
52
53 print("\n> Starting desktop stream...")
54 desktop.stream.start(require_auth=True)
55 auth_key = desktop.stream.get_auth_key()
56 stream_url = desktop.stream.get_url(auth_key=auth_key)
57 print(" - Stream URL:", stream_url)
58
59 # The webview needs to run on the main thread. That would mean that it would block the program execution.
60 # To avoid that, we run it in a separate process and send commands to it via a queue.
61 command_queue = Queue()
62 webview_process = Process(target=create_window, args=(stream_url, width, height, command_queue))
63 webview_process.start()
64
65 print("\n> Waiting 10 seconds for the stream to start...")
66 for i in range(10, 0, -1):
67 print(f" - {i} seconds remaining until the next step...")
68 time.sleep(1)
69
70 print("\n> Randomly moving mouse and right clicking 5 times...")
71 move_around(desktop, width, height)
72
73 input("\nPress enter to kill the sandbox and close the window...")
74
75 print("\n> Stopping desktop stream...")
76 desktop.stream.stop()
77 print(" - Desktop stream stopped")
78
79 print("\n> Closing webview...")
80 # When you want to close the window, send the 'close' command to the webview process.
81 command_queue.put('close')
82 webview_process.join()
83 print(" - Webview closed")
84
85 print("\n> Killing desktop sandbox...")
86 # Kill the sandbox.
87 desktop.kill()
88 print(" - Desktop sandbox killed")
89
90
91if __name__ == "__main__":

Callers 1

main.pyFile · 0.70

Calls 7

move_aroundFunction · 0.85
get_screen_sizeMethod · 0.80
get_auth_keyMethod · 0.80
get_urlMethod · 0.80
createMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected