Skip to main content
Send input to an additional process in an active operation, then collect its result. The SDK handles subprocess creation, SSE decoding, stdin delivery, and signals. Three cases preserve the parent lifetime explicitly:
  1. Send two ordered stdin writes and EOF; the child writes a completion file and both processes exit successfully.
  2. Send SIGTERM to a child, then release its parent to a successful exit.
  3. Release the parent while a ready child is still sleeping, so operation finalization ends the child.

Prerequisites

Complete Set up access. In a fresh project, run uv init --python 3.12 and uv add "contree-sdk[async]==0.5.1" "contree-client==0.6.0". The SDK reads the connection from your environment or saved profile; credentials stay in the local client and are not passed to guest code. The available tag:alpine:latest image supplies a POSIX shell, sleep, touch, and test. ContreeAsyncSession exposes operation handles. Each parent is disposable, has a 30-second execution limit, and waits on a bounded file condition. Start with main() and normal_interaction(); the named guest programs define the coordination conditions. stdin_open=True keeps the child input open. The first write uses close=False; the second uses close=True to send EOF. A child’s spid identifies it within its parent operation. One operation handle shares a single event reader across readiness, child results, and the final parent result.

Complete source

Save as interact.py and run uv run python interact.py. Representative output follows; child IDs and the parent-finalization signal can vary:
The signal case releases the parent only after verifying the child’s signal result. The parent-first case waits for /tmp/child-started before releasing the parent. After parent completion, it reads the child result through the underlying client. Finalization can close the log without a child exit event, so its exit code and signal may remain -1 (unknown). The SDK child wait() requires an exit event and cannot reconstruct that incomplete log; terminal parent completion still ends the VM and its children. These conditions avoid relying on a fixed delay for ordering. Replace READ_TWO_LINES and the messages to adapt the interaction. Exiting an operation context stops its main process if it is still running, waits for shutdown, and attempts cancellation when necessary. This cleanup also runs after a check, stream error, or the overall 120-second deadline fails. Cancellation and transport errors can leave a remote outcome uncertain; record parent.uuid to inspect existing work before retrying. Stdin writes are not retried because a failed response can follow successful byte delivery. Every parent is disposable, so no result images are retained. See Run subprocesses and send input and the SDK operation guide.