This guide runs the proxy client inside the sandbox, which means it needs a custom template and the code in the sandbox can bypass it. If you want E2B to tunnel the sandbox’s outbound traffic through your own SOCKS5 proxy with nothing running in the guest, see Bring your own proxy.
Setting up proxy tunneling
We will set up a proxy server on a GCP VM instance running Shadowsocks and use it to tunnel the Sandbox network traffic. This will allow you to use a dedicated IP address for outgoing requests.GCP VM setup
-
Create a firewall rule to allow all tcp/udp traffic to port 8388.
Replace
your-project-idwith your actual project ID. -
Create a VM instance with the following tags:
allow-shadowsocks.Replaceyour-project-idwith your actual project ID. -
After the VM is created, you can connect to it using the following command:
Replace
your-project-idwith your actual project ID.
Shadowsocks server setup (VM)
SSH into the VM and follow the instructions below to install and configure Shadowsocks.-
Install the necessary packages, if missing:
-
Download and install Shadowsocks (v1.24.0):
-
Create a shadowsocks configuration file:
Replace
STRONG_PASSWORD_HEREwith your own password./etc/shadowsocks/server.json -
Enable IP forwarding:
/etc/sysctl.d/99-shadowsocks.confOptional: Update the Ubuntu Firewall rules to allow traffic to port 8388:
-
Start the Shadowsocks server:
You should see the following in the console output:
-
Optional: Create a systemd service to start the Shadowsocks server on boot:
Reload the systemd daemon and start the service:/etc/systemd/system/ssserver.serviceYou can check the status of the service with the following command:
Shadowsocks client setup (sandbox)
Create a custom Sandbox template that uses the shadowsocks client to tunnel TCP traffic through the proxy server we set up above.- Local proxy
- Transparent proxy
Route only designated traffic through the proxy.
-
Create a configuration file for the shadowsocks client:
Replace
SERVER_IPwith the IP address of the proxy server andSTRONG_PASSWORD_HEREwith your own password.config.json -
Create a template file (
template.ts/template.py): -
Create a build script (
build.ts/build.py): -
Build the template using the build script:
Using the proxies
Create a new Sandbox from the built template and run a curl command to verify that the traffic is routed through the proxy:- Local proxy
- Transparent proxy
Only designated traffic should be routed through the proxy.You should see the IP address of the proxy server.