Basic Command Execution
You can run commands using shell syntax or by specifying command and arguments separately:- Async
- Sync
ContreeImage.run() and ContreeSession.run() for all options.Command Execution Mode
You can execute commands by specifying the executable path and arguments separately:- Async
- Sync
ContreeImage.run() and ContreeSession.run() for command execution details.Command vs Shell Mode
- Command mode: Use
command="/bin/ls"withargs=["-la", "/tmp"]for direct execution without shell interpretation - Shell mode: Use
shell="ls -la /tmp"for shell commands with pipes, redirects, and wildcards - Environment variables: Pass
env={"VAR": "value"}to set environment for command execution
Working with Files
You can upload and use files in your commands by specifying local file paths or pre-uploaded file objects:- Async
- Sync
File Upload Methods
You can provide files to commands in several ways:- Local file paths:
files=["/path/to/local/file.txt"]- Upload files directly - File mapping:
files={"dest.txt": "/local/source.txt"}- Upload with custom names - Pre-uploaded files:
files={"script.sh": uploaded_file_object}- Use files uploaded viaclient.files.upload()
Advanced I/O Handling
You can use Python I/O objects for more sophisticated input/output handling:- Async
- Sync
run() for I/O parameter details.Supported I/O Types
- StringIO: For text-based input/output
- BytesIO: For binary data handling
- File objects: Use
open()file handles directly - PIPE: Capture stderr/stdout as byte streams
- bytes type: Get output as bytes instead of strings
Subprocess-like Interface (Sync Only)
You can use a subprocess-like interface for more control over process execution:ContreeProcessSync for the full subprocess API.
Popen Features
- Process control: Use
wait(),communicate(), and checkreturncode - Environment variables: Pass custom
envdictionary - Working directory: Set
cwdparameter - Shell commands: Enable with
shell=True - Error handling: Check
returncodeandstderrfor failures
Command Parameters
Core Parameters
shell: Execute as shell command (e.g.,"ls -la | grep txt")command: Executable path (e.g.,"/bin/ls")args: Command arguments as tuple (e.g.,("-la", "/tmp"))stdin: Input data (string, bytes, or I/O object)env: Environment variables as dictionary
I/O Parameters
stdout: Redirect stdout (StringIO, BytesIO, file path, orbytes)stderr: Redirect stderr (StringIO, BytesIO, PIPE, orbytes)files: Upload files (list of paths or dict mapping)
Execution Parameters
cwd: Working directory inside containerdisposable: Whether to persist changes (default: True for runs, False for sessions)tag: Tag to assign to the resulting image after execution (e.g.tag="myapp:v2")
Result Objects
Command execution returns result objects with:stdout: Command output as string (or specified type)stderr: Error output as string (or specified type)exit_code: Process exit code (0 = success)uuid: UUID of the resulting image state