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

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.
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.58",
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
  };
@@ -27,6 +29,10 @@ export type JsonSchemaOutputFormat = BaseOutputFormat & {
27
29
  export type OutputFormat = JsonSchemaOutputFormat;
28
30
  export type ApiKeySource = 'user' | 'project' | 'org' | 'temporary';
29
31
  export type ConfigScope = 'local' | 'user' | 'project';
32
+ /**
33
+ * Allowed beta headers that can be passed via SDK options.
34
+ */
35
+ export type SdkBeta = 'context-1m-2025-08-07';
30
36
  export type McpStdioServerConfig = {
31
37
  type?: 'stdio';
32
38
  command: string;
@@ -403,6 +409,7 @@ export type SDKSystemMessage = {
403
409
  subtype: 'init';
404
410
  agents?: string[];
405
411
  apiKeySource: ApiKeySource;
412
+ betas?: string[];
406
413
  claude_code_version: string;
407
414
  cwd: string;
408
415
  tools: string[];
@@ -560,6 +567,7 @@ export type AgentDefinition = {
560
567
  disallowedTools?: string[];
561
568
  prompt: string;
562
569
  model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
570
+ criticalSystemReminder_EXPERIMENTAL?: string;
563
571
  };
564
572
  export type SettingSource = 'user' | 'project' | 'local';
565
573
  export type SdkPluginConfig = {
@@ -575,6 +583,16 @@ export type Options = {
575
583
  continue?: boolean;
576
584
  cwd?: string;
577
585
  disallowedTools?: string[];
586
+ /**
587
+ * Specify the base set of available built-in tools.
588
+ * - `string[]` - Array of specific tool names (e.g., `['Bash', 'Read', 'Edit']`)
589
+ * - `[]` (empty array) - Disable all built-in tools
590
+ * - `{ type: 'preset'; preset: 'claude_code' }` - Use all default Claude Code tools
591
+ */
592
+ tools?: string[] | {
593
+ type: 'preset';
594
+ preset: 'claude_code';
595
+ };
578
596
  env?: {
579
597
  [envVar: string]: string | undefined;
580
598
  };
@@ -587,6 +605,7 @@ export type Options = {
587
605
  * continuing the previous session. Use with --resume.
588
606
  */
589
607
  forkSession?: boolean;
608
+ betas?: SdkBeta[];
590
609
  hooks?: Partial<Record<HookEvent, HookCallbackMatcher[]>>;
591
610
  includePartialMessages?: boolean;
592
611
  maxThinkingTokens?: number;
@@ -621,6 +640,42 @@ export type Options = {
621
640
  * The message ID is expected to be from SDKAssistantMessage.uuid.
622
641
  */
623
642
  resumeSessionAt?: string;
643
+ /**
644
+ * Sandbox settings for command execution isolation.
645
+ *
646
+ * When enabled, commands are executed in a sandboxed environment that restricts
647
+ * filesystem and network access. This provides an additional security layer.
648
+ *
649
+ * **Important:** Filesystem and network restrictions are configured via permission
650
+ * rules, not via these sandbox settings:
651
+ * - Filesystem access: Use `Read` and `Edit` permission rules
652
+ * - Network access: Use `WebFetch` permission rules
653
+ *
654
+ * These sandbox settings control sandbox behavior (enabled, auto-allow, etc.),
655
+ * while the actual access restrictions come from your permission configuration.
656
+ *
657
+ * @example Enable sandboxing with auto-allow
658
+ * ```typescript
659
+ * sandbox: {
660
+ * enabled: true,
661
+ * autoAllowBashIfSandboxed: true
662
+ * }
663
+ * ```
664
+ *
665
+ * @example Configure network options (not restrictions)
666
+ * ```typescript
667
+ * sandbox: {
668
+ * enabled: true,
669
+ * network: {
670
+ * allowLocalBinding: true,
671
+ * allowUnixSockets: ['/var/run/docker.sock']
672
+ * }
673
+ * }
674
+ * ```
675
+ *
676
+ * @see https://docs.anthropic.com/en/docs/claude-code/settings#sandbox-settings
677
+ */
678
+ sandbox?: SandboxSettings;
624
679
  settingSources?: SettingSource[];
625
680
  stderr?: (data: string) => void;
626
681
  strictMcpConfig?: boolean;
@@ -656,4 +711,3 @@ export declare function unstable_v2_resumeSession(_sessionId: string, _options:
656
711
  * ```
657
712
  */
658
713
  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
- // (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.
2
+ // (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.
3
3
 
4
- // Version: 0.1.56
4
+ // Version: 0.1.58
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;
@@ -6479,6 +6495,7 @@ class ProcessTransport {
6479
6495
  try {
6480
6496
  const {
6481
6497
  additionalDirectories = [],
6498
+ betas,
6482
6499
  cwd,
6483
6500
  executable = isRunningWithBun() ? "bun" : "node",
6484
6501
  executableArgs = [],
@@ -6504,7 +6521,8 @@ class ProcessTransport {
6504
6521
  strictMcpConfig,
6505
6522
  canUseTool,
6506
6523
  includePartialMessages,
6507
- plugins
6524
+ plugins,
6525
+ sandbox
6508
6526
  } = this.options;
6509
6527
  const args = [
6510
6528
  "--output-format",
@@ -6523,6 +6541,9 @@ class ProcessTransport {
6523
6541
  }
6524
6542
  if (model)
6525
6543
  args.push("--model", model);
6544
+ if (betas && betas.length > 0) {
6545
+ args.push("--betas", betas.join(","));
6546
+ }
6526
6547
  if (jsonSchema) {
6527
6548
  args.push("--json-schema", JSON.stringify(jsonSchema));
6528
6549
  }
@@ -6547,6 +6568,18 @@ class ProcessTransport {
6547
6568
  if (disallowedTools.length > 0) {
6548
6569
  args.push("--disallowedTools", disallowedTools.join(","));
6549
6570
  }
6571
+ const { tools } = this.options;
6572
+ if (tools !== undefined) {
6573
+ if (Array.isArray(tools)) {
6574
+ if (tools.length === 0) {
6575
+ args.push("--tools", "");
6576
+ } else {
6577
+ args.push("--tools", tools.join(","));
6578
+ }
6579
+ } else {
6580
+ args.push("--tools", "default");
6581
+ }
6582
+ }
6550
6583
  if (mcpServers && Object.keys(mcpServers).length > 0) {
6551
6584
  args.push("--mcp-config", JSON.stringify({ mcpServers }));
6552
6585
  }
@@ -6589,7 +6622,8 @@ class ProcessTransport {
6589
6622
  if (this.options.resumeSessionAt) {
6590
6623
  args.push("--resume-session-at", this.options.resumeSessionAt);
6591
6624
  }
6592
- for (const [flag, value] of Object.entries(extraArgs)) {
6625
+ const effectiveExtraArgs = mergeSandboxIntoExtraArgs(extraArgs ?? {}, sandbox);
6626
+ for (const [flag, value] of Object.entries(effectiveExtraArgs)) {
6593
6627
  if (value === null) {
6594
6628
  args.push(`--${flag}`);
6595
6629
  } else {
@@ -15054,7 +15088,7 @@ function query({
15054
15088
  prompt,
15055
15089
  options
15056
15090
  }) {
15057
- const { systemPrompt, settingSources, ...rest } = options ?? {};
15091
+ const { systemPrompt, settingSources, sandbox, ...rest } = options ?? {};
15058
15092
  let customSystemPrompt;
15059
15093
  let appendSystemPrompt;
15060
15094
  if (systemPrompt === undefined) {
@@ -15070,16 +15104,18 @@ function query({
15070
15104
  const dirname2 = join5(filename, "..");
15071
15105
  pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
15072
15106
  }
15073
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.56";
15107
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.58";
15074
15108
  const {
15075
15109
  abortController = createAbortController(),
15076
15110
  additionalDirectories = [],
15077
15111
  agents,
15078
15112
  allowedTools = [],
15113
+ betas,
15079
15114
  canUseTool,
15080
15115
  continue: continueConversation,
15081
15116
  cwd: cwd2,
15082
15117
  disallowedTools = [],
15118
+ tools,
15083
15119
  env,
15084
15120
  executable = isRunningWithBun() ? "bun" : "node",
15085
15121
  executableArgs = [],
@@ -15133,6 +15169,7 @@ function query({
15133
15169
  const transport = new ProcessTransport({
15134
15170
  abortController,
15135
15171
  additionalDirectories,
15172
+ betas,
15136
15173
  cwd: cwd2,
15137
15174
  executable,
15138
15175
  executableArgs,
@@ -15156,12 +15193,14 @@ function query({
15156
15193
  settingSources: settingSources ?? [],
15157
15194
  allowedTools,
15158
15195
  disallowedTools,
15196
+ tools,
15159
15197
  mcpServers: allMcpServers,
15160
15198
  strictMcpConfig,
15161
15199
  canUseTool: !!canUseTool,
15162
15200
  hooks: !!hooks,
15163
15201
  includePartialMessages,
15164
- plugins
15202
+ plugins,
15203
+ sandbox
15165
15204
  });
15166
15205
  const initConfig = {
15167
15206
  systemPrompt: customSystemPrompt,