eust-w a89cd1b9b3 ✨ Let Claude Code run commands inside its own sandbox, by operator opt-in
With WF_CLAUDE_COMMAND_SANDBOX=true, Claude Code also gets Bash, run in
its built-in sandbox through --settings:

- The sandbox must start (failIfUnavailable), and no command may run
  outside it (allowUnsandboxedCommands: false).
- No network: an empty allowedDomains with strictAllowlist, since an
  absent allowlist leaves the network open. Local binding stays off,
  because it would also open every local port, Temporal's included.
- Commands cannot read the home directories, the CLI's home or the
  worker's own directory, except the workspace, a per-run scratch
  directory and WF_CLAUDE_COMMAND_READ_PATHS; they write only to the
  workspace and the scratch directory; credential variables are unset.
- WF_CLAUDE_COMMAND_ENV gives commands toolchain variables, such as the
  POC's read-only Go module cache.

The executor probes the sandbox first (Seatbelt on macOS; bubblewrap
and socat on Linux) and keeps file tools only where it cannot start,
saying so on the timeline. The adapter now writes the execution
contract into the prompt, for the tools the agent actually has.

scripts/check-claude-command-sandbox.ts checks a machine with one short
real session and judges each probe by its effect, not the agent's
account. On the local Mac every probe was blocked; the login keychain
remains reachable, because Claude Code's Seatbelt profile always allows
the security server. That limit is documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 14:48:16 +08:00

84 lines
2.9 KiB
JavaScript

import { resolve } from 'node:path';
import { environment, loadLocalEnvironment, startServices } from './local-services.mjs';
loadLocalEnvironment();
const root = process.cwd();
const productionWeb = process.env.WF_WEB_SERVE_MODE === 'production';
if (process.env.WF_WEB_SERVE_MODE && !['production', 'development'].includes(process.env.WF_WEB_SERVE_MODE))
throw new Error('WF_WEB_SERVE_MODE must be production or development.');
if (
process.env.WF_WEB_HOST &&
!['127.0.0.1', 'localhost', '::1'].includes(process.env.WF_WEB_HOST) &&
process.env.WF_LOCAL_ACCESS !== 'true'
)
throw new Error('A non-loopback development web listener requires WF_LOCAL_ACCESS=true.');
const worker = (role, token) => ({
name: role,
cwd: root,
args: ['--import', 'tsx', 'apps/worker/src/main.ts'],
env: environment([/^TEMPORAL_/, /^WF_CONTROL_PLANE_URL$/, /^WF_DISPATCH_TENANTS$/], {
WF_WORKER_ROLE: role,
[token]: process.env[token],
}),
});
await startServices(
[
{
name: 'git',
cwd: root,
args: ['--import', 'tsx', 'apps/git-service/src/main.ts'],
env: environment([/^WF_GIT_/]),
url: 'http://127.0.0.1:4504/health',
identity: 'git-storage',
},
{
name: 'api',
cwd: resolve(root, 'apps/api'),
args: ['--import', 'tsx', 'src/main.ts'],
env: environment([/^DATABASE_URL$/, /^WF_/, /^S3_/, /^OIDC_/, /^TEMPORAL_/, /^VAULT_/, /^PORT$/, /^HOST$/]),
url: 'http://127.0.0.1:4000/health',
identity: 'wishforge-control-plane',
},
{
name: 'provisioner',
cwd: root,
args: ['apps/provisioner/main.mjs'],
env: environment([
/^WF_PROVISIONER_/,
/^WF_LOCAL_/,
/^WF_TENANT_ID$/,
/^WF_RESOURCE_GRANT_SECRET$/,
/^WF_CONTROL_PLANE_URL$/,
/^TEMPORAL_/,
/^WF_GIT_ALLOW_LOCAL_HTTP$/,
/^WF_CODEBUDDY_BIN$/,
/^WF_CLAUDE_BIN$/,
/^WF_CLAUDE_LOCAL_AUTH_HOME$/,
/^WF_CLAUDE_COMMAND_(SANDBOX|READ_PATHS|ENV)$/,
]),
url: 'http://127.0.0.1:4450/healthz',
identity: 'wishforge-provisioner',
},
worker('coordinator', 'WF_WORKER_TOKEN'),
worker('deployer', 'WF_DEPLOYER_TOKEN'),
{
name: 'web',
cwd: resolve(root, 'apps/web'),
args: [
resolve(root, 'node_modules/next/dist/bin/next'),
productionWeb ? 'start' : 'dev',
'--hostname',
process.env.WF_WEB_HOST || '127.0.0.1',
'--port',
process.env.WF_WEB_PORT || '3000',
],
env: environment(
[/^WF_LOCAL_ACCESS$/, /^WF_LOCAL_ACCESS_FILE$/, /^WF_LOCAL_ALLOWED_ORIGINS$/, /^WF_LOCAL_API_TOKEN$/],
{ NODE_ENV: productionWeb ? 'production' : 'development' },
),
url: `http://127.0.0.1:${process.env.WF_WEB_PORT || '3000'}${process.env.WF_LOCAL_ACCESS === 'true' ? '/login' : '/api/session'}`,
},
],
'WishForge console: http://localhost:3000 · API: http://127.0.0.1:4000 · Temporal: http://127.0.0.1:8233',
);