mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(sandbox): per-session sandbox VMs with resource settings and provider arbitration
- Sandbox new root sessions by default with a per-session composer toggle; child sessions inherit their root session's mode (OM-82) - Run each sandboxed root session in its own microVM that mounts only the session's repository, with per-session CPU/memory overrides, Settings defaults, idle stop, and a cap on running VMs (OM-89) - Arbitrate shell sandboxing with other plugins (opencode-forge) through the shared opencode.sandbox-arbiter.v1 registry so exactly one provider sandboxes each call regardless of load order; fail closed on claim errors - Throw when another plugin rewrites a pinned sandbox shell setting - Tag sandboxed tool results with the owning provider and show it in the badge - Hint the agent to start Docker inside the VM only when OCM owns the session
This commit is contained in:
1 parent
ccdf75d803
commit
b21fdf5b94
48 files changed
+5666
-3375
No files matched your search
@@ -14,6 +14,7 @@ export * from './skills'
|
||||
export * from './internal-assistant'
|
||||
export * from './session-pins'
|
||||
export * from './session-permissions'
|
||||
export * from './session-sandbox'
|
||||
export * from './session-goals'
|
||||
export * from './internal-sessions'
|
||||
export * from './multi-runs'
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const SessionSandboxResourcesSchema = z.object({
|
||||
cpus: z.number().int().min(1).max(64),
|
||||
memoryMib: z.number().int().min(1024).max(1048576),
|
||||
});
|
||||
|
||||
export type SessionSandboxResources = z.infer<typeof SessionSandboxResourcesSchema>;
|
||||
|
||||
export const SessionSandboxSourceSchema = z.enum(['default', 'user']);
|
||||
|
||||
export type SessionSandboxSource = z.infer<typeof SessionSandboxSourceSchema>;
|
||||
|
||||
export const SetSessionSandboxRequestSchema = z
|
||||
.object({
|
||||
sandboxed: z.boolean().optional(),
|
||||
resources: SessionSandboxResourcesSchema.nullable().optional(),
|
||||
})
|
||||
.refine((value) => value.sandboxed !== undefined || value.resources !== undefined, {
|
||||
message: 'At least one of sandboxed or resources is required',
|
||||
});
|
||||
|
||||
export type SetSessionSandboxRequest = z.infer<typeof SetSessionSandboxRequestSchema>;
|
||||
|
||||
export const SessionSandboxStateSchema = z.object({
|
||||
sessionId: z.string(),
|
||||
rootSessionId: z.string(),
|
||||
sandboxed: z.boolean(),
|
||||
source: SessionSandboxSourceSchema,
|
||||
resources: SessionSandboxResourcesSchema.nullable(),
|
||||
effectiveResources: SessionSandboxResourcesSchema,
|
||||
lockedReason: z.enum(["child"]).nullable(),
|
||||
available: z.boolean(),
|
||||
});
|
||||
|
||||
export type SessionSandboxState = z.infer<typeof SessionSandboxStateSchema>;
|
||||
|
||||
export const SessionSandboxClaimSchema = z.object({
|
||||
sandboxed: z.boolean(),
|
||||
source: SessionSandboxSourceSchema,
|
||||
since: z.number(),
|
||||
});
|
||||
|
||||
export type SessionSandboxClaim = z.infer<typeof SessionSandboxClaimSchema>;
|
||||
@@ -4,6 +4,7 @@ import { OPENCODE_CONFIG_SOURCE_NAMES } from "../config/defaults";
|
||||
import { ColorThemeIdSchema, MANAGER_COLOR_THEME_ID } from "../themes";
|
||||
import { SessionPermissionModeSchema } from "./session-permissions";
|
||||
import { GOAL_MAX_CONTINUATIONS_MIN, GOAL_MAX_CONTINUATIONS_MAX } from "./limits";
|
||||
import { SessionSandboxResourcesSchema } from "./session-sandbox";
|
||||
|
||||
export const CustomCommandSchema = z.object({
|
||||
name: z.string(),
|
||||
@@ -148,9 +149,17 @@ export const DEFAULT_GIT_IDENTITY: GitIdentity = {
|
||||
email: '',
|
||||
};
|
||||
|
||||
export const DEFAULT_SANDBOX_IDLE_STOP_MINUTES = 30;
|
||||
export const DEFAULT_SANDBOX_MAX_RUNNING_VMS = 4;
|
||||
|
||||
export const SandboxPreferencesSchema = z.object({
|
||||
enabled: z.boolean(),
|
||||
gitCredentials: z.boolean().optional(),
|
||||
defaultForNewSessions: z.boolean().optional(),
|
||||
cpus: SessionSandboxResourcesSchema.shape.cpus.optional(),
|
||||
memoryMib: SessionSandboxResourcesSchema.shape.memoryMib.optional(),
|
||||
idleStopMinutes: z.number().int().min(1).max(1440).optional(),
|
||||
maxRunningVms: z.number().int().min(1).max(32).optional(),
|
||||
});
|
||||
|
||||
export type SandboxPreferences = z.infer<typeof SandboxPreferencesSchema>;
|
||||
@@ -158,6 +167,9 @@ export type SandboxPreferences = z.infer<typeof SandboxPreferencesSchema>;
|
||||
export const DEFAULT_SANDBOX_PREFERENCES: SandboxPreferences = {
|
||||
enabled: false,
|
||||
gitCredentials: false,
|
||||
defaultForNewSessions: true,
|
||||
idleStopMinutes: DEFAULT_SANDBOX_IDLE_STOP_MINUTES,
|
||||
maxRunningVms: DEFAULT_SANDBOX_MAX_RUNNING_VMS,
|
||||
};
|
||||
|
||||
export const SessionDefaultsSchema = z.object({
|
||||
|
||||
Reference in new issue
Block a user