What You’ll Learn
- How to create a sandbox with
network={"allow_out": [...]}for domain-level scraping control - How to upload and run a scraping script using Python’s
urllib(stdlib — no pip installs needed) - How to verify that allowed domains are reachable and blocked domains are not
- The pattern for containing scrapers that should only access specific sources
Prerequisites
- Declaw running locally or in the cloud (see Deployment)
DECLAW_API_KEYandDECLAW_DOMAINset in your environment- Outbound network access from your Declaw instance to
httpbin.org
This example is available in Python. TypeScript support coming soon.
Code Walkthrough
1. Create the sandbox with a network allow-list
httpbin.org is allowed. All other outbound connections — including DNS for other domains and direct IP connections — are blocked by the TCP proxy.
2. The scraper script
The scraper uses Python’s built-inurllib — no third-party packages required. The sandbox’s base Ubuntu image already has Python 3 installed:
3. Prove blocked domains are unreachable
Use a TCP socket test rather than an HTTP request — the block applies at the TCP layer, so even raw socket connections to blocked IPs are refused:4. Upload and run both tests
Expected Output
Use Cases
Price monitoring: Allow only the target retailer’s domain. The scraper cannot exfiltrate data to other servers or call home. News aggregation: Allowlist a set of news site domains. Even if the scraped page contains malicious JavaScript or links, the sandbox cannot follow them to unauthorized destinations. Competitive intelligence: Restrict the scraper to a defined list of competitor domains. Any unexpected outbound connection is blocked automatically.Domain Allowlist vs IP Allowlist
The network policy uses domain names, not IP addresses. The proxy resolves the domain to an IP at connection time and enforces the rule at the TCP layer. This means:allow_out: ["httpbin.org"]permits connections to any IP thathttpbin.orgresolves to- Direct IP connections (like
93.184.216.34) are blocked unless the IP resolves to an allowlisted domain at the time of the connection - CDNs and load balancers that share IPs across domains are handled correctly — the proxy checks the SNI (TLS) or Host header (HTTP) rather than just the IP