Skip to content

Add Code Interpreter tool type with sandboxed code execution#209

Draft
esafwan wants to merge 3 commits into
developfrom
claude/integrate-opensandbox-4kgCC
Draft

Add Code Interpreter tool type with sandboxed code execution#209
esafwan wants to merge 3 commits into
developfrom
claude/integrate-opensandbox-4kgCC

Conversation

@esafwan
Copy link
Copy Markdown
Contributor

@esafwan esafwan commented Mar 19, 2026

Summary

This PR introduces a new Code Interpreter tool type to HUF that enables agents to execute arbitrary code (Python, JavaScript, Bash, etc.) in isolated sandboxed environments with configurable network access policies. This complements the existing unsafe in-process code execution paths by providing a secure, resource-limited alternative.

Key Changes

Backend Implementation

  • New module huf/ai/sandbox_policy.py: Implements NetworkPolicy class to manage outbound network access for sandboxes with three modes:

    • disabled: No network access (air-gapped)
    • whitelist: Allow specific package registries (npm, pip, apt, brew, docker, cargo, gem, go, maven, nuget) and custom domains
    • open: Unrestricted outbound access
  • Updated huf/ai/sdk_tools.py:

    • Added handle_code_interpreter() function to execute code with sandbox configuration
    • Integrated Code Interpreter tool type into the tool dispatch logic
    • Passes network policy configuration from tool document to sandbox runtime
  • Extended Agent Tool Function DocType (agent_tool_function.py and .json):

    • Added Code Interpreter as a new tool type option
    • New fields for network policy configuration:
      • network_mode: Select between disabled/whitelist/open
      • network_presets: JSON array of preset registry IDs
      • allowed_domains: Newline-separated custom domain whitelist
    • Added validation for network policy configuration

Frontend Implementation

  • New component NetworkPolicyConfig.tsx:

    • Interactive UI for configuring sandbox network access
    • Mode selector (Disabled/Whitelist/Open) with visual indicators
    • Preset registry toggles with descriptions
    • Custom domain textarea for additional whitelisted domains
    • Conditional rendering based on selected mode
  • Updated tool creation form (ToolCreationForm.tsx):

    • Integrated NetworkPolicyConfig component for Code Interpreter tools
    • Conditional display of network policy section when tool type is Code Interpreter
  • Updated supporting files:

    • toolApi.ts: Added network policy fields to tool update payload
    • toolCreationForm.utils.ts: Added network policy schema validation
    • toolTemplates.json: Added Code Interpreter template configuration
    • agent.types.ts: Added Code Interpreter to ToolType union
    • SelectToolsModal.tsx, AgentFormPage.tsx: Pass network policy data through tool creation flow
    • ToolTemplateCard.tsx, toolIconMap.ts: Added Terminal icon for Code Interpreter tools

Notable Implementation Details

  • Network policy is deterministic: Built from tool configuration before sandbox creation, preventing LLM agents from influencing network access
  • Preset registry: Maintains a curated list of well-known package manager domains (npm, PyPI, apt, etc.) that can be toggled on/off
  • Extensible: Custom domains can be added beyond presets for organization-specific services
  • Validation: Both backend and frontend validate network policy configuration to prevent invalid states
  • Stub implementation: handle_code_interpreter() currently returns structured responses; actual sandbox runtime integration is a future step

Integration Points

The Code Interpreter tool integrates seamlessly with existing HUF infrastructure:

  • Works with the agent tool dispatch system in sdk_tools.py
  • Follows the same parameter schema pattern as other tool types
  • Supports all existing agent execution contexts (chat, flows, scheduling, etc.)
  • Network policy is passed through the tool invocation chain to the sandbox runtime

https://claude.ai/code/session_01LTWQ1MrfeoBMXJ1tmwqxea

claude added 3 commits March 18, 2026 17:55
Covers three integration approaches (new tool type, sandboxed custom
functions, long-lived session), full implementation plan for Approach A
(Run in Sandbox tool type), new DocType schema, opensandbox_tool.py
skeleton, sdk_tools.py wiring, security risks, deployment steps, and
effort estimates.

https://claude.ai/code/session_01LTWQ1MrfeoBMXJ1tmwqxea
Adds a new "Code Interpreter" tool type to Agent Tool Function with
configurable network access (disabled / whitelist / open).  Whitelist
mode supports one-click package-registry presets (npm, pip, apt, brew,
docker, cargo, gem, go, maven, nuget) plus free-form custom domains.

Backend:
- sandbox_policy.py: NetworkPolicy class with PRESET_DOMAINS registry;
  builds sandbox config dict consumed by the runtime integration point
- agent_tool_function.json: adds network_mode, network_presets,
  allowed_domains fields + Code Interpreter to types Select
- agent_tool_function.py: validate_code_interpreter(), Code Interpreter
  params schema (code, language, timeout)
- sdk_tools.py: routes Code Interpreter type to handle_code_interpreter();
  injects sandbox_config from NetworkPolicy; stub handler with clear
  wiring instructions for runtime integration

Frontend:
- NetworkPolicyConfig.tsx: reusable mode selector + preset chip grid +
  custom domains textarea; self-contained, no external state
- toolTemplates.json: new "Code Interpreter" template card (terminal icon)
- ToolTemplateCard / toolIconMap: terminal icon support
- agent.types.ts / toolTemplate.types.ts: Code Interpreter ToolType +
  network_mode / network_presets / allowed_domains in ToolFormData
- toolCreationForm.utils.ts: schema fields + shouldShowField + defaults
- ToolCreationForm.tsx: renders NetworkPolicyConfig when type is Code Interpreter
- toolApi.ts / AgentFormPage.tsx / SelectToolsModal.tsx: pass network
  fields through on create and update

https://claude.ai/code/session_01LTWQ1MrfeoBMXJ1tmwqxea
Covers network policy modes (disabled/whitelist/open), preset registry
usage, tool creation (UI, Desk, Python), sandbox runtime wiring, and
three deployment scenarios:
- Local bench + local Docker
- HUF in Docker + host Docker engine (shared network, host.docker.internal, extra_hosts)
- Remote VPS (DigitalOcean/Hetzner) with Caddy TLS, API key auth, UFW firewall

Includes testing examples (NetworkPolicy, handler stub, agent end-to-end,
curl), security notes, and full API reference.

https://claude.ai/code/session_01LTWQ1MrfeoBMXJ1tmwqxea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants