n8n-io/n8n · error

Workspace has no sandbox

Error message

Workspace has no sandbox

What it means

runInSandbox() reads `workspace.sandbox` and throws immediately if it is falsy. The helper exists to run a command in whatever sandbox a workspace provides; a workspace without a sandbox cannot execute anything, so it fails fast with a clear message instead of a confusing 'cannot read property executeCommand of undefined'.

Source

Thrown at packages/@n8n/agents/src/workspace/sandbox/run-in-sandbox.ts:45

		};
	};
}

/**
 * Execute a shell command in the sandbox and wait for completion.
 * Tries `executeCommand` first, falls back to `processes.spawn` + wait.
 *
 * The third argument may be a cwd string (legacy) or {@link RunInSandboxOptions}.
 */
export async function runInSandbox(
	workspace: SandboxCommandTarget,
	command: string,
	cwdOrOptions?: string | RunInSandboxOptions,
): Promise<{ exitCode: number; stdout: string; stderr: string }> {
	const options: RunInSandboxOptions =
		typeof cwdOrOptions === 'string' ? { cwd: cwdOrOptions } : (cwdOrOptions ?? {});
	const sandbox = workspace.sandbox;
	if (!sandbox) throw new Error('Workspace has no sandbox');

	if (sandbox.executeCommand) {
		const result = await sandbox.executeCommand(command, [], {
			cwd: options.cwd,
			abortSignal: options.abortSignal,
		});
		return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };
	}

	if (sandbox.processes) {
		const handle = await sandbox.processes.spawn(command, {
			cwd: options.cwd,
			abortSignal: options.abortSignal,
		});
		const result = await raceWithAbort(async () => await handle.wait(), options.abortSignal);
		return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr };
	}

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Construct the Workspace with a sandbox provider (Daytona/E2B/local) so workspace.sandbox is populated.
  2. Guard before calling: `if (!workspace.sandbox) throw new Error('configure a sandbox')`.
  3. Check the workspace preset/config includes a sandbox definition.

Example fix

// before
const ws = new Workspace({ /* no sandbox */ });
await runInSandbox(ws, 'ls');

// after
const ws = new Workspace({ sandbox: new DaytonaSandbox(opts) });
await runInSandbox(ws, 'ls');
Defensive patterns

Strategy: validation

Validate before calling

function hasSandbox(ws: { sandbox?: unknown }): boolean {
  return Boolean(ws.sandbox);
}
if (!hasSandbox(workspace)) {
  throw new Error('configure a sandbox before running commands');
}

Type guard

function hasSandbox(ws: unknown): ws is { sandbox: NonNullable<unknown> } {
  return typeof ws === 'object' && ws !== null && 'sandbox' in ws && Boolean((ws as { sandbox?: unknown }).sandbox);
}

Prevention

When it happens

Trigger: Calling runInSandbox(workspace, cmd) on a Workspace that was constructed without a sandbox, whose sandbox creation returned undefined, or whose sandbox was cleared. Also when a SandboxCommandTarget is passed that never had .sandbox populated.

Common situations: Workspace built in sandboxless mode (e.g. a dry-run/local-exec config); sandbox factory threw and the field was left unset; misconfigured workspace preset that omits the sandbox block.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/e4a4f2dcae1f2123. Report an issue: GitHub.