@anthropic-ai/claude-agent-sdk 0.1.56 → 0.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. package/cli.js +1174 -1179
  2. package/package.json +1 -1
  3. package/sandboxTypes.d.ts +144 -0
  4. package/sdk.d.ts +48 -1
  5. package/sdk.mjs +39 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Sandbox types for the Claude Code Agent SDK
3
+ *
4
+ * This file is the single source of truth for sandbox configuration types.
5
+ * Both the SDK and the settings validation import from here.
6
+ */
7
+ import { z } from 'zod';
8
+ /**
9
+ * Network configuration schema for sandbox.
10
+ */
11
+ export declare const SandboxNetworkConfigSchema: z.ZodOptional<z.ZodObject<{
12
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
13
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
14
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
15
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
16
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ allowUnixSockets?: string[];
19
+ allowAllUnixSockets?: boolean;
20
+ allowLocalBinding?: boolean;
21
+ httpProxyPort?: number;
22
+ socksProxyPort?: number;
23
+ }, {
24
+ allowUnixSockets?: string[];
25
+ allowAllUnixSockets?: boolean;
26
+ allowLocalBinding?: boolean;
27
+ httpProxyPort?: number;
28
+ socksProxyPort?: number;
29
+ }>>;
30
+ /**
31
+ * Sandbox settings schema.
32
+ */
33
+ export declare const SandboxSettingsSchema: z.ZodObject<{
34
+ enabled: z.ZodOptional<z.ZodBoolean>;
35
+ autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
36
+ allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
37
+ network: z.ZodOptional<z.ZodObject<{
38
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
39
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
40
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
41
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
42
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
43
+ }, "strip", z.ZodTypeAny, {
44
+ allowUnixSockets?: string[];
45
+ allowAllUnixSockets?: boolean;
46
+ allowLocalBinding?: boolean;
47
+ httpProxyPort?: number;
48
+ socksProxyPort?: number;
49
+ }, {
50
+ allowUnixSockets?: string[];
51
+ allowAllUnixSockets?: boolean;
52
+ allowLocalBinding?: boolean;
53
+ httpProxyPort?: number;
54
+ socksProxyPort?: number;
55
+ }>>;
56
+ ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
57
+ enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
58
+ excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
59
+ ripgrep: z.ZodOptional<z.ZodObject<{
60
+ command: z.ZodString;
61
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ command?: string;
64
+ args?: string[];
65
+ }, {
66
+ command?: string;
67
+ args?: string[];
68
+ }>>;
69
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
70
+ enabled: z.ZodOptional<z.ZodBoolean>;
71
+ autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
72
+ allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
73
+ network: z.ZodOptional<z.ZodObject<{
74
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
75
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
76
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
77
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
78
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
79
+ }, "strip", z.ZodTypeAny, {
80
+ allowUnixSockets?: string[];
81
+ allowAllUnixSockets?: boolean;
82
+ allowLocalBinding?: boolean;
83
+ httpProxyPort?: number;
84
+ socksProxyPort?: number;
85
+ }, {
86
+ allowUnixSockets?: string[];
87
+ allowAllUnixSockets?: boolean;
88
+ allowLocalBinding?: boolean;
89
+ httpProxyPort?: number;
90
+ socksProxyPort?: number;
91
+ }>>;
92
+ ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
93
+ enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
94
+ excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
95
+ ripgrep: z.ZodOptional<z.ZodObject<{
96
+ command: z.ZodString;
97
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
98
+ }, "strip", z.ZodTypeAny, {
99
+ command?: string;
100
+ args?: string[];
101
+ }, {
102
+ command?: string;
103
+ args?: string[];
104
+ }>>;
105
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
106
+ enabled: z.ZodOptional<z.ZodBoolean>;
107
+ autoAllowBashIfSandboxed: z.ZodOptional<z.ZodBoolean>;
108
+ allowUnsandboxedCommands: z.ZodOptional<z.ZodBoolean>;
109
+ network: z.ZodOptional<z.ZodObject<{
110
+ allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
111
+ allowAllUnixSockets: z.ZodOptional<z.ZodBoolean>;
112
+ allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
113
+ httpProxyPort: z.ZodOptional<z.ZodNumber>;
114
+ socksProxyPort: z.ZodOptional<z.ZodNumber>;
115
+ }, "strip", z.ZodTypeAny, {
116
+ allowUnixSockets?: string[];
117
+ allowAllUnixSockets?: boolean;
118
+ allowLocalBinding?: boolean;
119
+ httpProxyPort?: number;
120
+ socksProxyPort?: number;
121
+ }, {
122
+ allowUnixSockets?: string[];
123
+ allowAllUnixSockets?: boolean;
124
+ allowLocalBinding?: boolean;
125
+ httpProxyPort?: number;
126
+ socksProxyPort?: number;
127
+ }>>;
128
+ ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
129
+ enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
130
+ excludedCommands: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
131
+ ripgrep: z.ZodOptional<z.ZodObject<{
132
+ command: z.ZodString;
133
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
134
+ }, "strip", z.ZodTypeAny, {
135
+ command?: string;
136
+ args?: string[];
137
+ }, {
138
+ command?: string;
139
+ args?: string[];
140
+ }>>;
141
+ }, z.ZodTypeAny, "passthrough">>;
142
+ export type SandboxSettings = z.infer<typeof SandboxSettingsSchema>;
143
+ export type SandboxNetworkConfig = NonNullable<z.infer<typeof SandboxNetworkConfigSchema>>;
144
+ export type SandboxIgnoreViolations = NonNullable<SandboxSettings['ignoreViolations']>;
package/sdk.d.ts CHANGED
@@ -4,6 +4,8 @@ import type { UUID } from 'crypto';
4
4
  import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
5
5
  import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
6
6
  import { type z, type ZodRawShape, type ZodObject } from 'zod';
7
+ import type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations } from './sandboxTypes.js';
8
+ export type { SandboxSettings, SandboxNetworkConfig, SandboxIgnoreViolations };
7
9
  export type NonNullableUsage = {
8
10
  [K in keyof Usage]: NonNullable<Usage[K]>;
9
11
  };
@@ -575,6 +577,16 @@ export type Options = {
575
577
  continue?: boolean;
576
578
  cwd?: string;
577
579
  disallowedTools?: string[];
580
+ /**
581
+ * Specify the base set of available built-in tools.
582
+ * - `string[]` - Array of specific tool names (e.g., `['Bash', 'Read', 'Edit']`)
583
+ * - `[]` (empty array) - Disable all built-in tools
584
+ * - `{ type: 'preset'; preset: 'claude_code' }` - Use all default Claude Code tools
585
+ */
586
+ tools?: string[] | {
587
+ type: 'preset';
588
+ preset: 'claude_code';
589
+ };
578
590
  env?: {
579
591
  [envVar: string]: string | undefined;
580
592
  };
@@ -621,6 +633,42 @@ export type Options = {
621
633
  * The message ID is expected to be from SDKAssistantMessage.uuid.
622
634
  */
623
635
  resumeSessionAt?: string;
636
+ /**
637
+ * Sandbox settings for command execution isolation.
638
+ *
639
+ * When enabled, commands are executed in a sandboxed environment that restricts
640
+ * filesystem and network access. This provides an additional security layer.
641
+ *
642
+ * **Important:** Filesystem and network restrictions are configured via permission
643
+ * rules, not via these sandbox settings:
644
+ * - Filesystem access: Use `Read` and `Edit` permission rules
645
+ * - Network access: Use `WebFetch` permission rules
646
+ *
647
+ * These sandbox settings control sandbox behavior (enabled, auto-allow, etc.),
648
+ * while the actual access restrictions come from your permission configuration.
649
+ *
650
+ * @example Enable sandboxing with auto-allow
651
+ * ```typescript
652
+ * sandbox: {
653
+ * enabled: true,
654
+ * autoAllowBashIfSandboxed: true
655
+ * }
656
+ * ```
657
+ *
658
+ * @example Configure network options (not restrictions)
659
+ * ```typescript
660
+ * sandbox: {
661
+ * enabled: true,
662
+ * network: {
663
+ * allowLocalBinding: true,
664
+ * allowUnixSockets: ['/var/run/docker.sock']
665
+ * }
666
+ * }
667
+ * ```
668
+ *
669
+ * @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
670
+ */
671
+ sandbox?: SandboxSettings;
624
672
  settingSources?: SettingSource[];
625
673
  stderr?: (data: string) => void;
626
674
  strictMcpConfig?: boolean;
@@ -656,4 +704,3 @@ export declare function unstable_v2_resumeSession(_sessionId: string, _options:
656
704
  * ```
657
705
  */
658
706
  export declare function unstable_v2_prompt(_message: string, _options: SDKSessionOptions): Promise<SDKResultMessage>;
659
- export {};
package/sdk.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://docs.claude.com/en/docs/claude-code/legal-and-compliance.
3
3
 
4
- // Version: 0.1.56
4
+ // Version: 0.1.57
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -6458,6 +6458,22 @@ function logForSdkDebugging(message) {
6458
6458
  appendFileSync2(path, output);
6459
6459
  }
6460
6460
 
6461
+ // ../src/transport/sandboxUtils.ts
6462
+ function mergeSandboxIntoExtraArgs(extraArgs, sandbox) {
6463
+ const effectiveExtraArgs = { ...extraArgs };
6464
+ if (sandbox) {
6465
+ let settingsObj = { sandbox };
6466
+ if (effectiveExtraArgs.settings) {
6467
+ try {
6468
+ const existingSettings = JSON.parse(effectiveExtraArgs.settings);
6469
+ settingsObj = { ...existingSettings, sandbox };
6470
+ } catch {}
6471
+ }
6472
+ effectiveExtraArgs.settings = JSON.stringify(settingsObj);
6473
+ }
6474
+ return effectiveExtraArgs;
6475
+ }
6476
+
6461
6477
  // ../src/transport/ProcessTransport.ts
6462
6478
  class ProcessTransport {
6463
6479
  options;
@@ -6504,7 +6520,8 @@ class ProcessTransport {
6504
6520
  strictMcpConfig,
6505
6521
  canUseTool,
6506
6522
  includePartialMessages,
6507
- plugins
6523
+ plugins,
6524
+ sandbox
6508
6525
  } = this.options;
6509
6526
  const args = [
6510
6527
  "--output-format",
@@ -6547,6 +6564,18 @@ class ProcessTransport {
6547
6564
  if (disallowedTools.length > 0) {
6548
6565
  args.push("--disallowedTools", disallowedTools.join(","));
6549
6566
  }
6567
+ const { tools } = this.options;
6568
+ if (tools !== undefined) {
6569
+ if (Array.isArray(tools)) {
6570
+ if (tools.length === 0) {
6571
+ args.push("--tools", "");
6572
+ } else {
6573
+ args.push("--tools", tools.join(","));
6574
+ }
6575
+ } else {
6576
+ args.push("--tools", "default");
6577
+ }
6578
+ }
6550
6579
  if (mcpServers && Object.keys(mcpServers).length > 0) {
6551
6580
  args.push("--mcp-config", JSON.stringify({ mcpServers }));
6552
6581
  }
@@ -6589,7 +6618,8 @@ class ProcessTransport {
6589
6618
  if (this.options.resumeSessionAt) {
6590
6619
  args.push("--resume-session-at", this.options.resumeSessionAt);
6591
6620
  }
6592
- for (const [flag, value] of Object.entries(extraArgs)) {
6621
+ const effectiveExtraArgs = mergeSandboxIntoExtraArgs(extraArgs ?? {}, sandbox);
6622
+ for (const [flag, value] of Object.entries(effectiveExtraArgs)) {
6593
6623
  if (value === null) {
6594
6624
  args.push(`--${flag}`);
6595
6625
  } else {
@@ -15054,7 +15084,7 @@ function query({
15054
15084
  prompt,
15055
15085
  options
15056
15086
  }) {
15057
- const { systemPrompt, settingSources, ...rest } = options ?? {};
15087
+ const { systemPrompt, settingSources, sandbox, ...rest } = options ?? {};
15058
15088
  let customSystemPrompt;
15059
15089
  let appendSystemPrompt;
15060
15090
  if (systemPrompt === undefined) {
@@ -15070,7 +15100,7 @@ function query({
15070
15100
  const dirname2 = join5(filename, "..");
15071
15101
  pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
15072
15102
  }
15073
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.56";
15103
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.57";
15074
15104
  const {
15075
15105
  abortController = createAbortController(),
15076
15106
  additionalDirectories = [],
@@ -15080,6 +15110,7 @@ function query({
15080
15110
  continue: continueConversation,
15081
15111
  cwd: cwd2,
15082
15112
  disallowedTools = [],
15113
+ tools,
15083
15114
  env,
15084
15115
  executable = isRunningWithBun() ? "bun" : "node",
15085
15116
  executableArgs = [],
@@ -15156,12 +15187,14 @@ function query({
15156
15187
  settingSources: settingSources ?? [],
15157
15188
  allowedTools,
15158
15189
  disallowedTools,
15190
+ tools,
15159
15191
  mcpServers: allMcpServers,
15160
15192
  strictMcpConfig,
15161
15193
  canUseTool: !!canUseTool,
15162
15194
  hooks: !!hooks,
15163
15195
  includePartialMessages,
15164
- plugins
15196
+ plugins,
15197
+ sandbox
15165
15198
  });
15166
15199
  const initConfig = {
15167
15200
  systemPrompt: customSystemPrompt,