@@ -336,16 +336,18 @@ func (a *agent) init() {
336
336
// will not report anywhere.
337
337
a .scriptRunner .RegisterMetrics (a .prometheusRegistry )
338
338
339
- containerAPIOpts := []agentcontainers.Option {
340
- agentcontainers .WithExecer (a .execer ),
341
- agentcontainers .WithCommandEnv (a .sshServer .CommandEnv ),
342
- agentcontainers .WithScriptLogger (func (logSourceID uuid.UUID ) agentcontainers.ScriptLogger {
343
- return a .logSender .GetScriptLogger (logSourceID )
344
- }),
345
- }
346
- containerAPIOpts = append (containerAPIOpts , a .containerAPIOptions ... )
339
+ if a .devcontainers {
340
+ containerAPIOpts := []agentcontainers.Option {
341
+ agentcontainers .WithExecer (a .execer ),
342
+ agentcontainers .WithCommandEnv (a .sshServer .CommandEnv ),
343
+ agentcontainers .WithScriptLogger (func (logSourceID uuid.UUID ) agentcontainers.ScriptLogger {
344
+ return a .logSender .GetScriptLogger (logSourceID )
345
+ }),
346
+ }
347
+ containerAPIOpts = append (containerAPIOpts , a .containerAPIOptions ... )
347
348
348
- a .containerAPI = agentcontainers .NewAPI (a .logger .Named ("containers" ), containerAPIOpts ... )
349
+ a .containerAPI = agentcontainers .NewAPI (a .logger .Named ("containers" ), containerAPIOpts ... )
350
+ }
349
351
350
352
a .reconnectingPTYServer = reconnectingpty .NewServer (
351
353
a .logger .Named ("reconnecting-pty" ),
@@ -1106,6 +1108,9 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
1106
1108
if a .devcontainers {
1107
1109
a .logger .Info (ctx , "devcontainers are not supported on sub agents, disabling feature" )
1108
1110
a .devcontainers = false
1111
+ if err := a .containerAPI .Close (); err != nil {
1112
+ a .logger .Error (ctx , "disable container API" , slog .Error (err ))
1113
+ }
1109
1114
}
1110
1115
}
1111
1116
a .client .RewriteDERPMap (manifest .DERPMap )
@@ -1310,8 +1315,10 @@ func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(co
1310
1315
network .SetBlockEndpoints (manifest .DisableDirectConnections )
1311
1316
1312
1317
// Update the subagent client if the container API is available.
1313
- client := agentcontainers .NewSubAgentClientFromAPI (a .logger , aAPI )
1314
- a .containerAPI .UpdateSubAgentClient (client )
1318
+ if a .containerAPI != nil {
1319
+ client := agentcontainers .NewSubAgentClientFromAPI (a .logger , aAPI )
1320
+ a .containerAPI .UpdateSubAgentClient (client )
1321
+ }
1315
1322
}
1316
1323
return nil
1317
1324
}
@@ -1912,8 +1919,10 @@ func (a *agent) Close() error {
1912
1919
a .logger .Error (a .hardCtx , "script runner close" , slog .Error (err ))
1913
1920
}
1914
1921
1915
- if err := a .containerAPI .Close (); err != nil {
1916
- a .logger .Error (a .hardCtx , "container API close" , slog .Error (err ))
1922
+ if a .containerAPI != nil {
1923
+ if err := a .containerAPI .Close (); err != nil {
1924
+ a .logger .Error (a .hardCtx , "container API close" , slog .Error (err ))
1925
+ }
1917
1926
}
1918
1927
1919
1928
// Wait for the graceful shutdown to complete, but don't wait forever so
0 commit comments