@@ -25,8 +25,24 @@ while ($true) {
25
25
}
26
26
}
27
27
28
- # If the below fails, retrying probably will not help.
29
- Set-MpPreference - DisableRealtimeMonitoring$true - ExclusionPath$env: TEMP \sshd.exe
28
+ # Check if running in a Windows container
29
+ if (-not (Get-Command ' Set-MpPreference' - ErrorAction SilentlyContinue)) {
30
+ Write-Output " Set-MpPreference not available, skipping..."
31
+ }else {
32
+ Set-MpPreference - DisableRealtimeMonitoring$true - ExclusionPath$env: TEMP \sshd.exe
33
+ }
34
+
30
35
$env: CODER_AGENT_AUTH = " ${AUTH_TYPE} "
31
36
$env: CODER_AGENT_URL = " ${ACCESS_URL} "
32
- Start-Process - FilePath$env: TEMP \sshd.exe - ArgumentList" agent" - PassThru
37
+
38
+ # Check if we're running inside a Windows container!
39
+ $inContainer = $false
40
+ if ((Get-ItemProperty ' HKLM:\SYSTEM\CurrentControlSet\Control' - Name' ContainerType' - ErrorAction SilentlyContinue)-ne $null ) {
41
+ $inContainer = $true
42
+ }
43
+ if ($inContainer ) {
44
+ # If we're in a container, run in a the foreground!
45
+ Start-Process - FilePath$env: TEMP \sshd.exe - ArgumentList" agent" - Wait- NoNewWindow
46
+ }else {
47
+ Start-Process - FilePath$env: TEMP \sshd.exe - ArgumentList" agent" - PassThru
48
+ }